upload

package
v0.0.0-...-2538462 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package upload deals with uploading images and database to a FTP server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All(ctx context.Context, store DataStore, dbx *sqlx.DB, uploader Uploader) (int, error)

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

func CleanupOrphanedRemoteBlobs(ctx context.Context, dbx *sqlx.DB, uploader Uploader) (int, error)

CleanupOrphanedRemoteBlobs removes from the remote storage all blobs which are unknown to the database.

func GetThumbName

func GetThumbName(blobName string) string

GetThumbName gets the file name of a blob thumbnail.

func RevertThumbName

func RevertThumbName(thumbName string) string

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

func (d DataStore) GetBlobPath(blobName string) string

GetBlobPath gets the path to a blob.

func (DataStore) GetBlobThumbPath

func (d DataStore) GetBlobThumbPath(blobName string) string

GetBlobThumbPath gets the path to a blob thumbnail.

func (DataStore) GetDBPath

func (d DataStore) GetDBPath() string

GetDBPath gets the path to the database file.

func (DataStore) GetDataPath

func (d DataStore) GetDataPath(fpath string) string

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 NewFTP

func NewFTP(ctx context.Context, c FTPConfig) (*FTP, error)

NewFTP connects and authenticates to an FTP server.

func (*FTP) AtomicUpload

func (f *FTP) AtomicUpload(ctx context.Context, remotePath string, contents io.Reader) error

AtomicUpload implements Uploader.

func (*FTP) Close

func (f *FTP) Close() error

Close implements Uploader.

func (*FTP) DeleteFile

func (f *FTP) DeleteFile(_ context.Context, remotePath string) error

DeleteFile implements Uploader.

func (*FTP) ListFiles

func (f *FTP) ListFiles(_ context.Context, remotePath string) ([]string, error)

ListFiles implements Uploader.

func (*FTP) Upload

func (f *FTP) Upload(_ context.Context, remotePath string, contents io.Reader) error

Upload 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.

Jump to

Keyboard shortcuts

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