Documentation
¶
Overview ¶
Package upload deals with uploading images and database to a FTP server.
Index ¶
- func All(ctx context.Context, store DataStore, dbx *sqlx.DB, uploader Uploader) (int, error)
- func CleanupOrphanedRemoteBlobs(ctx context.Context, dbx *sqlx.DB, uploader Uploader) (int, error)
- func GetThumbName(blobName string) string
- func RevertThumbName(thumbName string) string
- type DataStore
- type FTP
- func (f *FTP) AtomicUpload(ctx context.Context, remotePath string, contents io.Reader) error
- func (f *FTP) Close() error
- func (f *FTP) DeleteFile(_ context.Context, remotePath string) error
- func (f *FTP) ListFiles(_ context.Context, remotePath string) ([]string, error)
- func (f *FTP) Upload(_ context.Context, remotePath string, contents io.Reader) error
- type FTPConfig
- type Uploader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func All ¶
All uploads all pending trains, until an error is hit or there are no more pending uploads. Also updates the database, and uploads the updated database.
func CleanupOrphanedRemoteBlobs ¶
CleanupOrphanedRemoteBlobs removes from the remote storage all blobs which are unknown to the database.
func GetThumbName ¶
GetThumbName gets the file name of a blob thumbnail.
func RevertThumbName ¶
RevertThumbName inverts the result of GetThumbName(), i.e. converts a thumbnail name back to the initial file name.
Types ¶
type DataStore ¶
type DataStore struct {
DataDir string `arg:"--data-dir,env:DATA_DIR" help:"Directory to store output data" default:"data" placeholder:"DIR"`
}
DataStore is a utility to centralize data store file system paths and access.
func (DataStore) GetBlobPath ¶
GetBlobPath gets the path to a blob.
func (DataStore) GetBlobThumbPath ¶
GetBlobThumbPath gets the path to a blob thumbnail.
func (DataStore) GetDataPath ¶
GetDataPath gets the path to a file in the top level data directory.
type FTP ¶
type FTP struct {
// contains filtered or unexported fields
}
FTP is a FTP uploader. Use NewFTP to create an instance.
func (*FTP) AtomicUpload ¶
AtomicUpload implements Uploader.
func (*FTP) DeleteFile ¶
DeleteFile implements Uploader.
type FTPConfig ¶
type FTPConfig struct { Host string `arg:"--upload-ftp-host,env:UPLOAD_FTP_HOST" help:"FTP hostname" placeholder:"HOST"` Port uint16 `arg:"--upload-ftp-port,env:UPLOAD_FTP_PORT" help:"FTP port" default:"21" placeholder:"PORT"` User string `arg:"--upload-ftp-user,env:UPLOAD_FTP_USER" help:"FTP username" placeholder:"USER"` Password string `arg:"--upload-ftp-password,env:UPLOAD_FTP_PASSWORD" help:"FTP password" placeholder:"PASS"` PWD string `` /* 132-byte string literal not displayed */ }
FTPConfig is the configuration to connect to a FTP server.
type Uploader ¶
type Uploader interface { // Upload uploads a file. Upload(ctx context.Context, remotePath string, contents io.Reader) error // AtomicUpload uploads a file, trying to swap out the file in an atomic operation. AtomicUpload(ctx context.Context, remotePath string, contents io.Reader) error // ListFiles lists all regular files in a remote directory. // Any non-regular files (e.g. directories) are to be ignored. ListFiles(ctx context.Context, remotePath string) ([]string, error) // DeleteFile deletes a regular file at the given remote path. DeleteFile(ctx context.Context, remotePath string) error // Close terminates the connection and frees any resources. Close() error }
Uploader is an interface for interaction with a remote file storage location.