files

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2024 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dump added in v0.14.0

func Dump() (allFiles map[int64]io.ReadCloser, err error)

Dump dumps all saved files This only includes the raw files, no db entries.

func FileStat

func FileStat(filename string) (os.FileInfo, error)

FileStat stats a file. This is an exported function to be able to test this from outide of the package

func GetTables

func GetTables() []interface{}

GetTables returns all structs which are also a table.

func InitFileHandler

func InitFileHandler()

InitFileHandler creates a new file handler for the file backend we want to use

func InitTestFileFixtures

func InitTestFileFixtures(t *testing.T)

InitTestFileFixtures initializes file fixtures

func InitTestFileHandler

func InitTestFileHandler()

InitTestFileHandler initializes a new memory file system for testing

func InitTests

func InitTests()

InitTests handles the actual bootstrapping of the test env

func IsErrFileDoesNotExist

func IsErrFileDoesNotExist(err error) bool

IsErrFileDoesNotExist checks if an error is ErrFileDoesNotExist

func IsErrFileIsNotUnsplashFile added in v0.14.0

func IsErrFileIsNotUnsplashFile(err error) bool

IsErrFileIsNotUnsplashFile checks if an error is ErrFileIsNotUnsplashFile

func IsErrFileIsTooLarge

func IsErrFileIsTooLarge(err error) bool

IsErrFileIsTooLarge checks if an error is ErrFileIsTooLarge

func SetEngine

func SetEngine() (err error)

SetEngine sets the xorm.Engine

Types

type ErrFileDoesNotExist

type ErrFileDoesNotExist struct {
	FileID int64
}

ErrFileDoesNotExist defines an error where a file does not exist in the db

func (ErrFileDoesNotExist) Error

func (err ErrFileDoesNotExist) Error() string

Error is the error implementation of ErrFileDoesNotExist

type ErrFileIsNotUnsplashFile added in v0.14.0

type ErrFileIsNotUnsplashFile struct {
	FileID int64
}

ErrFileIsNotUnsplashFile defines an error where a file is not downloaded from unsplash. Used in cases whenever unsplash information about a file is requested, but the file was not downloaded from unsplash.

func (ErrFileIsNotUnsplashFile) Error added in v0.14.0

func (err ErrFileIsNotUnsplashFile) Error() string

Error is the error implementation of ErrFileIsNotUnsplashFile

type ErrFileIsTooLarge

type ErrFileIsTooLarge struct {
	Size uint64
}

ErrFileIsTooLarge defines an error where a file is larger than the configured limit

func (ErrFileIsTooLarge) Error

func (err ErrFileIsTooLarge) Error() string

Error is the error implementation of ErrFileIsTooLarge

type File

type File struct {
	ID   int64  `xorm:"bigint autoincr not null unique pk" json:"id"`
	Name string `xorm:"text not null" json:"name"`
	Mime string `xorm:"text null" json:"mime"`
	Size uint64 `xorm:"bigint not null" json:"size"`

	Created     time.Time `xorm:"created" json:"created"`
	CreatedByID int64     `xorm:"bigint not null" json:"-"`

	File afero.File `xorm:"-" json:"-"`
	// This ReadCloser is only used for migration purposes. Use with care!
	// There is currentlc no better way of doing this.
	FileContent []byte `xorm:"-" json:"-"`
}

File holds all information about a file

func Create

func Create(f io.Reader, realname string, realsize uint64, a web.Auth) (file *File, err error)

Create creates a new file from an FileHeader

func CreateWithMime added in v0.15.0

func CreateWithMime(f io.Reader, realname string, realsize uint64, a web.Auth, mime string) (file *File, err error)

CreateWithMime creates a new file from an FileHeader and sets its mime type

func CreateWithMimeAndSession added in v0.18.0

func CreateWithMimeAndSession(s *xorm.Session, f io.Reader, realname string, realsize uint64, a web.Auth, mime string, checkFileSizeLimit bool) (file *File, err error)

func (*File) Delete

func (f *File) Delete() (err error)

Delete removes a file from the DB and the file system

func (*File) LoadFileByID

func (f *File) LoadFileByID() (err error)

LoadFileByID returns a file by its ID

func (*File) LoadFileMetaByID

func (f *File) LoadFileMetaByID() (err error)

LoadFileMetaByID loads everything about a file without loading the actual file

func (*File) Save added in v0.14.0

func (f *File) Save(fcontent io.Reader) (err error)

Save saves a file to storage

func (File) TableName

func (File) TableName() string

TableName is the table name for the files table

Jump to

Keyboard shortcuts

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