storage

package
v0.0.0-...-bdb90e4 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Admin

func Admin(u *User) boolean.Wrapper

func ApplyDelta

func ApplyDelta(oldData []byte, deltas []Delta) ([]byte, error)

func ApplyVersionToContent

func ApplyVersionToContent(fileContent []byte, version FileVersion) ([]byte, error)

func ConvertFileToTypes

func ConvertFileToTypes(file *File) *types.File

func ConvertFileVersionToTypes

func ConvertFileVersionToTypes(version *FileVersion) *types.FileVersion

func ConvertFileVersionsToTypes

func ConvertFileVersionsToTypes(versions []FileVersion) []types.FileVersion

func ConvertFilesToTypes

func ConvertFilesToTypes(files []File) []types.File

func ConvertUserToTypes

func ConvertUserToTypes(user *User) *types.User

func NewTxAdapter

func NewTxAdapter(tx *sqlx.Tx) types.Tx

func SerializeDelta

func SerializeDelta(deltas []Delta) ([]byte, error)

Types

type Delta

type Delta struct {
	Offset int    // Смещение, где начинается изменение
	Data   []byte // Новые данные
	Length int    // Количество байтов для удаления (если 0 — просто вставка)
}

func DeserializeDelta

func DeserializeDelta(data []byte) ([]Delta, error)

type File

type File struct {
	ID            int `db:"id" json:"id"`
	UserID        int `db:"user_id" json:"user_id"`
	LastVersionID int `db:"last_version_id" json:"last_version_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"`
}

func ConvertFileFromTypes

func ConvertFileFromTypes(file *types.File) *File

func ConvertFilesFromTypes

func ConvertFilesFromTypes(files []types.File) []File

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 FileVersion

type FileVersion struct {
	FileID      int       `db:"file_id"`
	UserID      int       `db:"user_id"`
	Version     int       `db:"version"`
	FullVersion bool      `db:"full_version"`
	Delta       []byte    `db:"delta"`
	ChangeType  string    `db:"change_type"`
	CreatedAt   time.Time `db:"created_at"`
}

func ConvertFileVersionFromTypes

func ConvertFileVersionFromTypes(version *types.FileVersion) *FileVersion

type Properties

type Properties struct {
}

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) AddFileVersion

func (s *Storage) AddFileVersion(version FileVersion) error

func (*Storage) BeginTx

func (s *Storage) BeginTx() (*Tx, 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) DeleteFileVersion

func (s *Storage) DeleteFileVersion(fileID int, version int) error

func (*Storage) DeleteFileVersions

func (s *Storage) DeleteFileVersions(fileID int) 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) GetFileHistory

func (s *Storage) GetFileHistory(fileID int) ([]FileVersion, error)

func (*Storage) GetFileVersion

func (s *Storage) GetFileVersion(fileID int, version int) (FileVersion, error)

func (*Storage) GetFileVersions

func (s *Storage) GetFileVersions(fileID int) ([]FileVersion, error)

func (*Storage) GetImageFiles

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

func (*Storage) GetLastFileVersion

func (s *Storage) GetLastFileVersion(fileID int) (FileVersion, 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) RestoreFileToVersion

func (s *Storage) RestoreFileToVersion(fileID int, targetVersion int) ([]byte, 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 Tx

type Tx struct {
	*sqlx.Tx
}

type TxAdapter

type TxAdapter struct {
	*sqlx.Tx
}

func (*TxAdapter) Exec

func (ta *TxAdapter) Exec(query string, args ...interface{}) (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"`
}

func ConvertUserFromTypes

func ConvertUserFromTypes(user *types.User) *User

Jump to

Keyboard shortcuts

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