storage

package
v0.0.0-...-4266db3 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Admin

func Admin(u *User) boolean.Wrapper

Types

type File

type File struct {
	ID         int `db:"id" json:"id"`
	UserID     int `db:"user_id" json:"user_id"`
	Metadata   FileMetadata
	Status     string    `db:"status" json:"status"`
	Data       []byte    `db:"data" json:"data"`
	CreatedAt  time.Time `db:"created_at" json:"created_at"`
	ModifiedAt time.Time `db:"last_modified_at" json:"modified_at"`
}

type FileMetadata

type FileMetadata struct {
	Name        string `db:"filename" json:"filename"`
	Extension   string `db:"extension" json:"extension"`
	Size        int    `db:"filesize" json:"filesize"`
	HashSum     string `db:"hash_sum" json:"hash_sum"`
	Description string `db:"description,omitempty" json:"description,omitempty"`
}

type Storage

type Storage struct {
	DB *sqlx.DB
}

func InitDatabase

func InitDatabase(config *config.Config) (*Storage, error)

func (*Storage) AddFile

func (s *Storage) AddFile(f *File) error

func (*Storage) AddFileTx

func (s *Storage) AddFileTx(tx *sqlx.Tx, f *File) error

func (*Storage) CheckUser

func (s *Storage) CheckUser(username string) (bool, error)

func (*Storage) CloseDatabase

func (s *Storage) CloseDatabase() error

func (*Storage) DeleteAllFiles

func (s *Storage) DeleteAllFiles(userID int) error

func (*Storage) DeleteFile

func (s *Storage) DeleteFile(f *File) error

func (*Storage) DeleteUser

func (s *Storage) DeleteUser(username string) error

func (*Storage) GetAllFiles

func (s *Storage) GetAllFiles(userID int) ([]File, error)

func (*Storage) GetAllUsers

func (s *Storage) GetAllUsers() ([]User, error)

func (*Storage) GetFile

func (s *Storage) GetFile(userID int, filename string) (*File, error)

func (*Storage) GetImageFiles

func (s *Storage) GetImageFiles(userID int) ([]File, error)

func (*Storage) GetUser

func (s *Storage) GetUser(username string) (User, error)

func (*Storage) Query

func (s *Storage) Query(command string) (*sql.Rows, error)

func (*Storage) RenameFile

func (s *Storage) RenameFile(f *File) error

func (*Storage) SaveNewUser

func (s *Storage) SaveNewUser(u *User) error

func (*Storage) UpdateFile

func (s *Storage) UpdateFile(f *File, newData []byte) error

func (*Storage) UpdateFileMetadata

func (s *Storage) UpdateFileMetadata(userID int, req struct {
	Filename    string `json:"filename"`
	Extension   string `json:"extension"`
	Description string `json:"description"`
	OldName     string `json:"oldname"`
}) error

func (*Storage) UpdateUserInfo

func (s *Storage) UpdateUserInfo(username string, updates map[string]interface{}) error

type User

type User struct {
	UserID   int    `db:"id" json:"id"`
	Username string `db:"username" json:"username"`
	Email    string `db:"email" json:"email"`
	Password string `db:"password" json:"password"`
	Protocol string `db:"hashprotocol" json:"hashprotocol"`
	Admin    int    `db:"admin" json:"admin"`
}

Jump to

Keyboard shortcuts

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