internal

package
v0.0.0-...-732bfc7 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2022 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const MaxThumbnailWidth = 250

MaxThumbnailWidth ...

Variables

This section is empty.

Functions

func CacheFolder

func CacheFolder(db *beepboop.DB, folder *Folder) error

CacheFolder caches a Folder

func DetectContentType

func DetectContentType(r io.ReadSeeker) (string, error)

DetectContentType determines the MIME type of a given file

func FilenameToUUID

func FilenameToUUID(filename string) string

FilenameToUUID returns an UUID from a filename

func GetArchiveWalker

func GetArchiveWalker(filename, mime string) (archiver.Walker, error)

GetArchiveWalker ...

func Hash

func Hash(s string) string

Hash returns the SHA1 hash of a string

func IsFolder

func IsFolder(root, relPath string) bool

IsFolder returns whether a relative path is a folder

func IsThumbnailSupported

func IsThumbnailSupported(mime string) bool

IsThumbnailSupported returns whether thumbnails can be created for the specified mime type

func Salt

func Salt() string

Salt returns a random salt

func UncacheFolder

func UncacheFolder(db *beepboop.DB, folderName string) error

UncacheFolder uncaches a Folder

Types

type ErrFileAlreadyExists

type ErrFileAlreadyExists struct {
	File string
}

ErrFileAlreadyExists ...

func (ErrFileAlreadyExists) Error

func (err ErrFileAlreadyExists) Error() string

type ErrFolderConfigNotFound

type ErrFolderConfigNotFound struct {
	Folder string
}

ErrFolderConfigNotFound ...

func (ErrFolderConfigNotFound) Error

func (err ErrFolderConfigNotFound) Error() string

type ErrFolderNotWritable

type ErrFolderNotWritable struct{}

ErrFolderNotWritable ...

func (ErrFolderNotWritable) Error

func (err ErrFolderNotWritable) Error() string

type ErrInheritedConfigPasswordChange

type ErrInheritedConfigPasswordChange struct{}

ErrInheritedConfigPasswordChange ...

func (ErrInheritedConfigPasswordChange) Error

type ErrInvalidAccessType

type ErrInvalidAccessType struct {
	AccessType string
}

ErrInvalidAccessType ...

func (ErrInvalidAccessType) Error

func (err ErrInvalidAccessType) Error() string

type ErrPasswordScoreTooLow

type ErrPasswordScoreTooLow struct {
	Score int
}

ErrPasswordScoreTooLow ...

func (ErrPasswordScoreTooLow) Error

func (err ErrPasswordScoreTooLow) Error() string

type ErrReadWritePasswordMatch

type ErrReadWritePasswordMatch struct{}

ErrReadWritePasswordMatch ...

func (ErrReadWritePasswordMatch) Error

func (err ErrReadWritePasswordMatch) Error() string

type ErrUnsupportedFileFormat

type ErrUnsupportedFileFormat struct {
	MIME string
}

ErrUnsupportedFileFormat ...

func (ErrUnsupportedFileFormat) Error

func (err ErrUnsupportedFileFormat) Error() string

type ErrWrongPassword

type ErrWrongPassword struct{}

ErrWrongPassword ...

func (ErrWrongPassword) Error

func (err ErrWrongPassword) Error() string

type File

type File struct {
	Name      string     `json:"name"`
	Root      string     `json:"root"`
	RelPath   string     `json:"rel_path"`
	Tags      []string   `json:"tags"`
	MIME      string     `json:"mime"`
	Size      int64      `json:"size"`
	Uploaded  time.Time  `json:"uploaded"`
	Public    bool       `json:"public"`
	Thumbnail *Thumbnail `json:"thumbnail,omitempty"`
}

File ...

func (*File) Create

func (f *File) Create(content io.Reader, overwrite bool) error

Create ...

func (*File) Delete

func (f *File) Delete() error

Delete ...

func (*File) GetInternalFilename

func (f *File) GetInternalFilename() string

GetInternalFilename ...

func (*File) GetThumbnail

func (f *File) GetThumbnail(retryAfter time.Duration) (*Thumbnail, error)

GetThumbnail ...

func (*File) GetThumbnailBounds

func (f *File) GetThumbnailBounds(retryAfter time.Duration) (*image.Rectangle, error)

GetThumbnailBounds ...

func (*File) HasTag

func (f *File) HasTag(tag string) bool

HasTag ...

func (*File) Move

func (f *File) Move(relPath string) error

Move ...

func (*File) Open

func (f *File) Open() (FileReader, error)

Open ...

func (*File) Save

func (f *File) Save() error

Save ...

type FileReader

type FileReader interface {
	http.File
	os.FileInfo
	MimeType() string
}

FileReader ...

type Folder

type Folder struct {
	Root             string       `json:"root"`
	RelPath          string       `json:"rel_path"`
	Config           FolderConfig `json:"config"`
	ConfigInherited  bool         `json:"config_inherited"`
	ConfigRootFolder string       `json:"config_root"`
	CachedSubfolders []string     `json:"cached_subfolders"`
	CachedFiles      []*File      `json:"cached_files"`
}

Folder ...

func GetCachedFolder

func GetCachedFolder(db *beepboop.DB, folderName string) (*Folder, error)

GetCachedFolder returns a cached Folder

func GetFolder

func GetFolder(root, relPath string) (*Folder, error)

GetFolder returns a new Folder from a handle to a .razbox file

func (*Folder) CacheFile

func (f *Folder) CacheFile(file *File)

CacheFile adds a file to the list of cached files

func (*Folder) CacheSubfolder

func (f *Folder) CacheSubfolder(subfolder string)

CacheSubfolder adds a subfolder to the list of cached subfolders

func (*Folder) EnsureAccess

func (f *Folder) EnsureAccess(accessType string, sess *beepboop.Session) error

EnsureAccess returns an error if the access token doesn't permit access for the given access type

func (*Folder) EnsureReadAccess

func (f *Folder) EnsureReadAccess(sess *beepboop.Session) error

EnsureReadAccess returns an error if the access token doesn't permit read access

func (*Folder) EnsureWriteAccess

func (f *Folder) EnsureWriteAccess(sess *beepboop.Session) error

EnsureWriteAccess returns an error if the access token doesn't permit write access

func (*Folder) GetAccessToken

func (f *Folder) GetAccessToken(accessType string) (beepboop.AccessMap, error)

GetAccessToken returns an access token that permits access of the given access type

func (*Folder) GetFile

func (f *Folder) GetFile(basename string) (*File, error)

GetFile returns the file in the folder with the given basename

func (*Folder) GetFiles

func (f *Folder) GetFiles() []*File

GetFiles returns the files in the folder

func (*Folder) GetMaxUploadSizeMB

func (f *Folder) GetMaxUploadSizeMB() int64

GetMaxUploadSizeMB returns the maximum allowed upload size in MBs

func (*Folder) GetPasswordHash

func (f *Folder) GetPasswordHash(accessType string) (string, error)

GetPasswordHash returns the password hash of the given access type

func (*Folder) GetSubfolders

func (f *Folder) GetSubfolders() []string

GetSubfolders returns the subfolders

func (*Folder) Search

func (f *Folder) Search(tag string) []*File

Search returns the files that contain the given tag

func (*Folder) SetPassword

func (f *Folder) SetPassword(accessType, pw string) error

SetPassword sets the password for the given access type

func (*Folder) SetPasswords

func (f *Folder) SetPasswords(readPw, writePw string) error

SetPasswords generates a random salt and sets and read and write passwords

func (*Folder) SetReadPassword

func (f *Folder) SetReadPassword(readPw string) error

SetReadPassword sets the read password

func (*Folder) SetWritePassword

func (f *Folder) SetWritePassword(writePw string) error

SetWritePassword sets the write password

func (*Folder) TestPassword

func (f *Folder) TestPassword(accessType, pw string) bool

TestPassword returns true if the given password matches the password for the given access type

func (*Folder) TestReadPassword

func (f *Folder) TestReadPassword(readPw string) bool

TestReadPassword returns true if the given password matches the read password

func (*Folder) TestWritePassword

func (f *Folder) TestWritePassword(writePw string) bool

TestWritePassword returns true if the given password matches the write password

func (*Folder) UncacheFile

func (f *Folder) UncacheFile(filename string)

UncacheFile removes a file from the list of cached files

func (*Folder) UncacheSubfolder

func (f *Folder) UncacheSubfolder(subfolder string)

UncacheSubfolder removes a subfolder from the list of cached subfolders

type FolderConfig

type FolderConfig struct {
	Salt            string `json:"salt"`
	ReadPassword    string `json:"read_pw"`
	WritePassword   string `json:"write_pw"`
	MaxFileSizeMB   int64  `json:"max_file_size"`
	MaxFolderSizeMB int64  `json:"max_folder_size"`
	Subfolders      bool   `json:"subfolders"`
}

FolderConfig stores the folder's passwords and other congfiguration

type Thumbnail

type Thumbnail struct {
	Data      []byte          `json:"data"`
	MIME      string          `json:"mime"`
	Bounds    image.Rectangle `json:"bounds"`
	Timestamp time.Time       `json:"timestamp"`
}

Thumbnail contains a thumbnail image in bytes + the MIME type and bounds

func GetThumbnail

func GetThumbnail(filename string, mime string) (*Thumbnail, error)

GetThumbnail returns the thumbnail of a media file

Jump to

Keyboard shortcuts

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