controller

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 26, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMultipartFormFileNotFound = &APIError{
		http.StatusBadRequest,
		"file[] not found in Multipart form",
		errors.New("file[] not found in Multipart form"),
		nil,
	}
	ErrMultipartFileWrong = &APIError{
		http.StatusBadRequest,
		"wrong file data in multipart form, one needs to be specified",
		errors.New("wrong file data in multipart form, one needs to be specified"),
		nil,
	}
	ErrWrongDate = &APIError{
		http.StatusBadRequest,
		"couldn't parse date",
		errors.New("couldn't parse date"),
		nil,
	}
	ErrMetadataLength = &APIError{
		http.StatusBadRequest,
		"file metadata length doesn't match number of files in request",
		errors.New("file metadata length doesn't match number of files in request"),
		nil,
	}
	ErrBucketNotFound = &APIError{
		http.StatusNotFound,
		"bucket not found",
		errors.New("bucket not found"),
		nil,
	}
	ErrFileNotFound = &APIError{
		http.StatusNotFound,
		"file not found",
		errors.New("file not found"),
		nil,
	}
	ErrFileNotUploaded = &APIError{
		http.StatusForbidden,
		"file not uploaded",
		errors.New("file not uploaded"),
		nil,
	}
)

Functions

func GetUserSession added in v0.4.0

func GetUserSession(headers http.Header) map[string]any

func Version

func Version() string

Types

type APIError

type APIError struct {
	// contains filtered or unexported fields
}

func BadDataError

func BadDataError(err error, publicMessage string) *APIError

func FailedToInitializeMetadataError

func FailedToInitializeMetadataError(err error) *APIError

func FileTooBigError

func FileTooBigError(filename string, size, maxSize int) *APIError

func FileTooSmallError

func FileTooSmallError(filename string, size, minSize int) *APIError

func ForbiddenError

func ForbiddenError(err error, publicMessage string) *APIError

func InternalServerError

func InternalServerError(err error) *APIError

func NewAPIError added in v0.1.1

func NewAPIError(
	statusCode int,
	publicMessage string,
	err error,
	data map[string]interface{},
) *APIError

func WrongMetadataFormatError

func WrongMetadataFormatError(err error) *APIError

func (*APIError) Error

func (a *APIError) Error() string

func (*APIError) ExtendError

func (a *APIError) ExtendError(msg string) *APIError

func (*APIError) GetDataString added in v0.4.0

func (a *APIError) GetDataString(k string) string

func (*APIError) PublicResponse

func (a *APIError) PublicResponse() *ErrorResponse

func (*APIError) SetData added in v0.4.0

func (a *APIError) SetData(k string, v any)

func (*APIError) StatusCode

func (a *APIError) StatusCode() int

type Antivirus added in v0.4.0

type Antivirus interface {
	ScanReader(r io.ReaderAt) *APIError
}

type BucketMetadata

type BucketMetadata struct {
	ID                   string
	MinUploadFile        int
	MaxUploadFile        int
	PresignedURLsEnabled bool
	DownloadExpiration   int
	CreatedAt            string
	UpdatedAt            string
	CacheControl         string
}

type ContentStorage

type ContentStorage interface {
	PutFile(
		ctx context.Context,
		content io.ReadSeeker,
		filepath, contentType string,
	) (string, *APIError)
	GetFile(ctx context.Context, filepath string, headers http.Header) (*File, *APIError)
	CreatePresignedURL(
		ctx context.Context,
		filepath string,
		expire time.Duration,
	) (string, *APIError)
	GetFileWithPresignedURL(
		ctx context.Context, filepath, signature string, headers http.Header,
	) (*File, *APIError)
	DeleteFile(ctx context.Context, filepath string) *APIError
	ListFiles(ctx context.Context) ([]string, *APIError)
}

type Controller

type Controller struct {
	// contains filtered or unexported fields
}

func New

func New(
	publicURL string,
	apiRootPrefix string,
	hasuraAdminSecret string,
	metadataStorage MetadataStorage,
	contentStorage ContentStorage,
	imageTransformer *image.Transformer,
	av Antivirus,
	logger *logrus.Logger,
) *Controller

func (*Controller) DeleteBrokenMetadata

func (ctrl *Controller) DeleteBrokenMetadata(ctx *gin.Context)

func (*Controller) DeleteFile

func (ctrl *Controller) DeleteFile(ctx *gin.Context)

func (*Controller) DeleteOrphans

func (ctrl *Controller) DeleteOrphans(ctx *gin.Context)

func (*Controller) GetFile

func (ctrl *Controller) GetFile(ctx *gin.Context)

func (*Controller) GetFileInformation

func (ctrl *Controller) GetFileInformation(ctx *gin.Context)

func (*Controller) GetFilePresignedURL

func (ctrl *Controller) GetFilePresignedURL(ctx *gin.Context)

func (*Controller) GetFileWithPresignedURL added in v0.1.1

func (ctrl *Controller) GetFileWithPresignedURL(ctx *gin.Context)

func (*Controller) Health

func (ctrl *Controller) Health(ctx *gin.Context)

func (*Controller) ListBrokenMetadata

func (ctrl *Controller) ListBrokenMetadata(ctx *gin.Context)

func (*Controller) ListNotUploaded

func (ctrl *Controller) ListNotUploaded(ctx *gin.Context)

func (*Controller) ListOrphans

func (ctrl *Controller) ListOrphans(ctx *gin.Context)

func (*Controller) OpenAPI

func (ctrl *Controller) OpenAPI(ctx *gin.Context)

func (*Controller) SetupRouter

func (ctrl *Controller) SetupRouter(
	trustedProxies []string,
	apiRootPrefix string,
	corsOrigins []string,
	corsAllowCredentials bool,
	middleware ...gin.HandlerFunc,
) (*gin.Engine, error)

func (*Controller) UpdateFile

func (ctrl *Controller) UpdateFile(ctx *gin.Context)

func (*Controller) UploadFile

func (ctrl *Controller) UploadFile(ctx *gin.Context)

func (*Controller) Version

func (ctrl *Controller) Version(ctx *gin.Context)

type ErrorResponse

type ErrorResponse struct {
	Message string                 `json:"message"`
	Data    map[string]interface{} `json:"data,omitempty"`
}

Used to standardized the output of the handers' response.

type FakeReadCloserWrapper

type FakeReadCloserWrapper struct {
	*bytes.Reader
}

func NewP

func NewP(b []byte) *FakeReadCloserWrapper

func (*FakeReadCloserWrapper) Close

func (p *FakeReadCloserWrapper) Close() error

type File added in v0.2.0

type File struct {
	ContentType   string
	ContentLength int64
	Etag          string
	StatusCode    int
	Body          io.ReadCloser
	ExtraHeaders  http.Header
}

type FileMetadata

type FileMetadata struct {
	ID               string         `json:"id"`
	Name             string         `json:"name"`
	Size             int64          `json:"size"`
	BucketID         string         `json:"bucketId"`
	ETag             string         `json:"etag"`
	CreatedAt        string         `json:"createdAt"`
	UpdatedAt        string         `json:"updatedAt"`
	IsUploaded       bool           `json:"isUploaded"`
	MimeType         string         `json:"mimeType"`
	UploadedByUserID string         `json:"uploadedByUserId"`
	Metadata         map[string]any `json:"metadata"`
}

type FileResponse added in v0.1.1

type FileResponse struct {
	// contains filtered or unexported fields
}

func NewFileResponse added in v0.1.1

func NewFileResponse(
	fileID string,
	contentType string,
	contentLength int64,
	etag string,
	cacheControl string,
	lastModified string,
	statusCode int,
	reader io.ReadCloser,
	name string,
	headers http.Header,
) *FileResponse

func (*FileResponse) Write added in v0.1.1

func (r *FileResponse) Write(ctx *gin.Context)

type FileSummary

type FileSummary struct {
	ID         string `json:"id"`
	Name       string `json:"name"`
	IsUploaded bool   `json:"isUploaded"`
	BucketID   string `json:"bucketId"`
}

type GetFilePresignedURLRequest

type GetFilePresignedURLRequest struct {
	FileID string
}

type GetFilePresignedURLResponse

type GetFilePresignedURLResponse struct {
	Error      *ErrorResponse `json:"error,omitempty"`
	URL        string         `json:"url,omitempty"`
	Expiration int            `json:"expiration,omitempty"`
}

type GetFileResponse

type GetFileResponse struct {
	Error *ErrorResponse `json:"error"`
}

Only used if the request fails.

type GetFileWithPresignedURLRequest added in v0.1.1

type GetFileWithPresignedURLRequest struct {
	Expires int
	// contains filtered or unexported fields
}

type ListBrokenMetadataResponse

type ListBrokenMetadataResponse struct {
	Metadata []FileSummary `json:"metadata"`
}

type ListOrphansResponse

type ListOrphansResponse struct {
	Files []string `json:"files"`
}

type MetadataStorage

type MetadataStorage interface {
	GetBucketByID(ctx context.Context, id string, headers http.Header) (BucketMetadata, *APIError)
	GetFileByID(ctx context.Context, id string, headers http.Header) (FileMetadata, *APIError)
	InitializeFile(
		ctx context.Context,
		id, name string, size int64, bucketID, mimeType string,
		headers http.Header,
	) *APIError
	PopulateMetadata(
		ctx context.Context,
		id, name string, size int64, bucketID, etag string, IsUploaded bool, mimeType string,
		metadata map[string]any,
		headers http.Header) (FileMetadata, *APIError,
	)
	SetIsUploaded(
		ctx context.Context,
		fileID string,
		isUploaded bool,
		headers http.Header,
	) *APIError
	DeleteFileByID(ctx context.Context, fileID string, headers http.Header) *APIError
	ListFiles(ctx context.Context, headers http.Header) ([]FileSummary, *APIError)
	InsertVirus(
		ctx context.Context,
		fileID, filename, virus string,
		userSession map[string]any,
		headers http.Header,
	) *APIError
}

type UpdateFileResponse

type UpdateFileResponse struct {
	*FileMetadata
	Error *ErrorResponse `json:"error,omitempty"`
}

type UploadFileResponse

type UploadFileResponse struct {
	ProcessedFiles []FileMetadata `json:"processedFiles,omitempty"`
	Error          *ErrorResponse `json:"error,omitempty"`
}

this type is used to ensure we respond consistently no matter the case.

type VersionResponse

type VersionResponse struct {
	BuildVersion string `json:"buildVersion"`
}

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL