storage

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2021 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileMetaDatabase

type FileMetaDatabase interface {
	Connect() error
	WriteFile(sf *StoredFile) error
	GetFile(id string) (*StoredFile, error)
	GetAllFiles() ([]*StoredFile, error)
	GetAllExpired() ([]*StoredFile, error)
	DeleteFile(id string) error
}

FileMetaDatabase is for storing additional meta information on each file, e.g. the time a file has been uploaded or more imporantly when the file should be expired.

On startup, we check for every entry that is expired and delete it accordingly.

type FileStorage

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

FileStorage is the abstraction layer for storing uploaded files. It consists of a file system where the physical files are written to and a seperate database, where it stores metadata for each file.

func NewFileStorage

func NewFileStorage() *FileStorage

func (*FileStorage) Cleanup

func (fs *FileStorage) Cleanup() error

Cleanup uses the meta database to check for all files that have expired and deletes them accordingly.

func (*FileStorage) StoreFile

func (fs *FileStorage) StoreFile(rff *request.RequestFormFile, expiration int64) (*StoredFile, error)

type FileSystem

type FileSystem interface {
	// CreateFile writes the content of given reader to a file
	// with given name.
	// Always returns if the file was partly written to disk.
	CreateFile(r io.Reader, name string) (bool, error)

	DeleteFile(id string) error
	GetFile(id string) (*os.File, error)
	Exists(id string) (bool, error)
}

type LocalFileSystem

type LocalFileSystem struct {
	FolderPath string
}

func NewLocalFileStorage

func NewLocalFileStorage(path string) *LocalFileSystem

func (LocalFileSystem) CreateFile

func (l LocalFileSystem) CreateFile(r io.Reader, name string) (bool, error)

func (LocalFileSystem) DeleteFile

func (l LocalFileSystem) DeleteFile(id string) error

func (LocalFileSystem) Exists

func (l LocalFileSystem) Exists(id string) (bool, error)

func (LocalFileSystem) GetFile

func (l LocalFileSystem) GetFile(id string) (*os.File, error)

type SqliteFileMetaDatabase

type SqliteFileMetaDatabase struct {
	DbFolderPath string
	DbFilePath   string
}

func NewSqliteFileMetaDatabase

func NewSqliteFileMetaDatabase(folderPath string) *SqliteFileMetaDatabase

func (*SqliteFileMetaDatabase) Connect

func (s *SqliteFileMetaDatabase) Connect() error

func (*SqliteFileMetaDatabase) DeleteFile

func (s *SqliteFileMetaDatabase) DeleteFile(id string) error

func (*SqliteFileMetaDatabase) GetAllExpired

func (s *SqliteFileMetaDatabase) GetAllExpired() ([]*StoredFile, error)

func (*SqliteFileMetaDatabase) GetAllFiles

func (s *SqliteFileMetaDatabase) GetAllFiles() ([]*StoredFile, error)

func (*SqliteFileMetaDatabase) GetFile

func (s *SqliteFileMetaDatabase) GetFile(id string) (*StoredFile, error)

func (*SqliteFileMetaDatabase) WriteFile

func (s *SqliteFileMetaDatabase) WriteFile(sf *StoredFile) error

type StoredFile

type StoredFile struct {
	Id         string
	UploadedAt int64
	ExpiresAt  int64
	MimeType   string
	Size       int64
}

func (*StoredFile) String

func (sf *StoredFile) String() string

Jump to

Keyboard shortcuts

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