Documentation
¶
Index ¶
- type DirectUploadToken
- type DirectWritableUploadFileStoreProvider
- type InPlaceUploadFileStoreProvider
- type JSONLineUploadFileVerifier
- type JobModeStore
- type LocalFileUploadToken
- type LocalUploadFileStoreProvider
- type NopWaitUploadFileVerifier
- type Store
- type UploadFileStore
- func (s *UploadFileStore) GetResult(token UploadToken, req map[string]any) (UploadResult, error)
- func (s *UploadFileStore) GetUploadToken(id string, verifier UploadFileVerifier, fieldID string) UploadToken
- func (s *UploadFileStore) SetResultOnCompletedUpload(token UploadToken, uploadError error) error
- func (s *UploadFileStore) SetResultOnStartingUpload(token UploadToken) error
- type UploadFileStoreProvider
- type UploadFileVerifier
- type UploadResult
- type UploadStatus
- type UploadToken
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DirectUploadToken ¶
type DirectUploadToken struct {
// ID identifies the file location uploaded to this server directly.
ID string `json:"id"`
}
DirectUploadToken is a UploadToken for uploading the target file to API directly.
func (*DirectUploadToken) GetHash ¶
func (d *DirectUploadToken) GetHash() string
GetHash implements UploadToken.
func (*DirectUploadToken) GetID ¶
func (d *DirectUploadToken) GetID() string
GetID implements UploadToken.
func (*DirectUploadToken) GetType ¶
func (d *DirectUploadToken) GetType() string
GetType implements UploadToken.
type DirectWritableUploadFileStoreProvider ¶
type DirectWritableUploadFileStoreProvider interface {
// Write writes file with given io.Writer interaface to the file with the given ID.
Write(token UploadToken, reader io.Reader) error
}
type InPlaceUploadFileStoreProvider ¶ added in v0.57.1
type InPlaceUploadFileStoreProvider struct{}
InPlaceUploadFileStoreProvider is an implementation of UploadFileStore that reads the file in place.
func (*InPlaceUploadFileStoreProvider) GetUploadToken ¶ added in v0.57.1
func (i *InPlaceUploadFileStoreProvider) GetUploadToken(id string) UploadToken
GetUploadToken implements UploadFileStoreProvider.
func (*InPlaceUploadFileStoreProvider) Read ¶ added in v0.57.1
func (i *InPlaceUploadFileStoreProvider) Read(token UploadToken) (io.ReadCloser, error)
Read implements UploadFileStoreProvider.
type JSONLineUploadFileVerifier ¶
type JSONLineUploadFileVerifier struct {
MaxLineSizeInBytes int
}
func (*JSONLineUploadFileVerifier) Verify ¶
func (j *JSONLineUploadFileVerifier) Verify(storeProvider UploadFileStoreProvider, token UploadToken) error
Verify implements UploadFileVerifier.
type JobModeStore ¶ added in v0.57.1
type JobModeStore struct {
// contains filtered or unexported fields
}
JobModeStore is a Store implementation for job mode. Job mode does not run the web server, so files cannot be uploaded from a browser; instead this store resolves file form inputs from local file paths given in the inspection request values.
func NewJobModeStore ¶ added in v0.57.1
func NewJobModeStore() *JobModeStore
NewJobModeStore creates a new JobModeStore.
func (*JobModeStore) GetResult ¶ added in v0.57.1
func (s *JobModeStore) GetResult(token UploadToken, req map[string]any) (UploadResult, error)
GetResult resolves the file for the given token from the local file path in the request values, verifies it, and returns a completed UploadResult. It returns an error when the token is unknown or no path was provided.
func (*JobModeStore) GetUploadToken ¶ added in v0.57.1
func (s *JobModeStore) GetUploadToken(id string, verifier UploadFileVerifier, fieldID string) UploadToken
GetUploadToken issues a token for the given ID and records the form field ID and verifier so that GetResult can resolve the file later.
type LocalFileUploadToken ¶ added in v0.57.1
type LocalFileUploadToken struct {
// FilePath identifies the file location uploaded to this server locally.
FilePath string `json:"filepath"`
}
LocalFileUploadToken is a UploadToken for uploading local files via file path.
func (*LocalFileUploadToken) GetHash ¶ added in v0.57.1
func (l *LocalFileUploadToken) GetHash() string
GetHash implements UploadToken.
func (*LocalFileUploadToken) GetID ¶ added in v0.57.1
func (l *LocalFileUploadToken) GetID() string
GetID implements UploadToken.
func (*LocalFileUploadToken) GetType ¶ added in v0.57.1
func (l *LocalFileUploadToken) GetType() string
GetType implements UploadToken.
type LocalUploadFileStoreProvider ¶
type LocalUploadFileStoreProvider struct {
// contains filtered or unexported fields
}
LocalUploadFileStoreProvider is an implementation of UploadFileStore that stores files in the local file system.
func NewLocalUploadFileStoreProvider ¶
func NewLocalUploadFileStoreProvider(directoryPath string) *LocalUploadFileStoreProvider
NewLocalUploadFileStoreProvider creates a new LocalUploadFileStore.
func (*LocalUploadFileStoreProvider) GetUploadToken ¶
func (l *LocalUploadFileStoreProvider) GetUploadToken(id string) UploadToken
GetUploadToken implements UploadFileStoreProvider.
func (*LocalUploadFileStoreProvider) Read ¶
func (l *LocalUploadFileStoreProvider) Read(token UploadToken) (io.ReadCloser, error)
func (*LocalUploadFileStoreProvider) Write ¶
func (l *LocalUploadFileStoreProvider) Write(token UploadToken, reader io.Reader) error
type NopWaitUploadFileVerifier ¶
type NopWaitUploadFileVerifier struct {
// WaitTimeInMs is the time to wait before returning the veification result.
WaitTimeInMs int
// Error is the error returned from Verify function after waiting the WaitTimeInMs.
Error error
}
NopWaitUploadFileVerifier just waits the specified time without doing anything on the file.
func (*NopWaitUploadFileVerifier) Verify ¶
func (n *NopWaitUploadFileVerifier) Verify(storeProvider UploadFileStoreProvider, token UploadToken) error
Verify implements UploadFileVerifier.
type Store ¶ added in v0.57.1
type Store interface {
GetUploadToken(id string, verifier UploadFileVerifier, fieldID string) UploadToken
GetResult(token UploadToken, req map[string]any) (UploadResult, error)
}
Store is the store interface form tasks depend on. Server mode and job mode inject different implementations of it.
type UploadFileStore ¶
type UploadFileStore struct {
StoreProvider UploadFileStoreProvider
// contains filtered or unexported fields
}
UploadFileStore manages file uploads.
func NewUploadFileStore ¶
func NewUploadFileStore(storeProvider UploadFileStoreProvider) *UploadFileStore
NewUploadFileStore creates a new UploadFileStore.
func (*UploadFileStore) GetResult ¶
func (s *UploadFileStore) GetResult(token UploadToken, req map[string]any) (UploadResult, error)
GetResult returns the result of the upload with given token. The req parameter is unused in this implementation; it exists so job-mode stores can read local file paths from the request values.
func (*UploadFileStore) GetUploadToken ¶
func (s *UploadFileStore) GetUploadToken(id string, verifier UploadFileVerifier, fieldID string) UploadToken
GetUploadToken returns the token to upload it from frontend. The ID must be combination of a known string and random string to make it harder to guess it from outside.
func (*UploadFileStore) SetResultOnCompletedUpload ¶
func (s *UploadFileStore) SetResultOnCompletedUpload(token UploadToken, uploadError error) error
SetResultOnCompletedUpload notify the file upload is completed and start verifier.
func (*UploadFileStore) SetResultOnStartingUpload ¶
func (s *UploadFileStore) SetResultOnStartingUpload(token UploadToken) error
SetResultOnStartingUpload sets the upload status to Uploading. It returns an error if the token is not found.
type UploadFileStoreProvider ¶
type UploadFileStoreProvider interface {
// Generate a UploadToken for frontend
GetUploadToken(id string) UploadToken
// Read returns the io.ReadCloser interface to read the file with the given ID.
// The caller MUST close the returned ReadCloser.
Read(token UploadToken) (io.ReadCloser, error)
}
type UploadFileVerifier ¶
type UploadFileVerifier interface {
// Verify checks the file. This returns an error if invalid.
Verify(storeProvider UploadFileStoreProvider, token UploadToken) error
}
UploadFileVerifier verifies uploaded files (e.g., file type checks).
type UploadResult ¶
type UploadResult struct {
// Token is an UploadToken associated with the file.
Token UploadToken
// StoreProvider provides the way of getting the uploaded file with the given token.
StoreProvider UploadFileStoreProvider
// Status is the current state of the upload.
Status UploadStatus
// UploadError contains any error that occurred during the upload process itself
UploadError error
// VerificationError contains any error returned by the UploadFileVerifier.
VerificationError error
// VerificationCount is the attempt count of the verification logic. This value is preventing the race condition in verification steps.
VerificationCount int
}
UploadResult holds the result of an upload operation.
func (*UploadResult) GetReader ¶
func (r *UploadResult) GetReader() (io.ReadCloser, error)
GetReader returns an io.ReadCloser for reading the uploaded file. The caller MUST close the returned ReadCloser.
type UploadStatus ¶
type UploadStatus int
UploadStatus represents the status of an upload (Waiting or Completed).
const ( // UploadStatusWaiting indicates this file is not yet uploaded or in progress of upload. UploadStatusWaiting UploadStatus = 0 // UploadStatusUploading indicates this file is being uploaded. UploadStatusUploading UploadStatus = 1 // UploadStatusVerifying indicates the file was uploaded but this is under verifying. UploadStatusVerifying UploadStatus = 2 // UploadStatusComplete indicates the file has uploaded successfully. UploadStatusCompleted UploadStatus = 3 )
type UploadToken ¶
type UploadToken interface {
// GetType returns the type of token specifying the methods to upload the file.
GetType() string
// GetID returns the unique identifier of upload files.
GetID() string
// GetHash returns a unique string calculated from all the field of the implementation.
// This must be calculated from ALL the field because this is for checking if 2 instances are identical.
GetHash() string
}
UploadToken is the type given to the frontend to receive the file. This currently exects files are uploaded to API directly, but in future this may support the upload using signed URLs as well. All token implements this type must be serializable as JSON.