db

package
v0.0.0-...-88723d5 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2022 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAlreadyExists      = errors.New("An entry with the same name is already there")
	ErrInvalidPath        = errors.New("The path is invalid")
	ErrCannotCreateFolder = errors.New("Cannot create folder")
	ErrNonEmptyFolder     = errors.New("The folder is not empty")
)
View Source
var (
	ErrUserAlreadyExists = errors.New("The user already exists")
)

Functions

func CreateFile

func CreateFile(file *File) error

Create a file and all the folders needed

func CreateFolder

func CreateFolder(f *Folder) error

Act like `mkdir -p`

func CreateUser

func CreateUser(user *User) error

func DeleteFile

func DeleteFile(id uint64, userid int64) error

func DeleteFolder

func DeleteFolder(id uint64, userid int64) error

func DeleteFolderRecursive

func DeleteFolderRecursive(id uint64, userid int64) error

func EditFile

func EditFile(file *File, userid int64) error

func EditFolder

func EditFolder(folder *Folder, userid int64) error

func UpdateUser

func UpdateUser(user *User) error

Types

type File

type File struct {
	ID       uint64 `gorm:"primaryKey" json:"fileID"`
	Name     string `gorm:"non null" json:"name"`
	Path     string `gorm:"non null" json:"path"`
	ParentID uint64 `gorm:"non null" json:"parentID"`
	Owner    int64  `gorm:"non null" json:"owner"`

	Header string `gorm:"non null" json:"header"`
	KeyEnc string `gorm:"non null" json:"key"`
	Nonce  string `gorm:"non null" json:"nonce"`

	FileID string `gorm:"not null" json:"-"`
}

func GetFileByID

func GetFileByID(id uint64, userid int64) (*File, error)

func GetFilesInFolder

func GetFilesInFolder(parent *Folder) ([]*File, error)

func (*File) GetParent

func (f *File) GetParent() (*Folder, error)

type Folder

type Folder struct {
	ID       uint64 `gorm:"primaryKey" json:"folderID"`
	Name     string `gorm:"non null" json:"name"`
	Path     string `gorm:"non null" json:"path"`
	Owner    int64  `gorm:"non null" json:"owner"`
	ParentID uint64 `json:"parentID"`
}

func GetFolderByID

func GetFolderByID(id uint64, userid int64) (*Folder, error)

func GetFolderByPath

func GetFolderByPath(path string, userid int64) (*Folder, error)

func GetFoldersInFolder

func GetFoldersInFolder(parent *Folder) ([]*Folder, error)

func GetRootOf

func GetRootOf(userID int64) (*Folder, error)

func (*Folder) GetParent

func (f *Folder) GetParent() (*Folder, error)

type FolderContent

type FolderContent struct {
	Files  []*File   `gorm:"foreignKey:ID" json:"files"`
	Folder []*Folder `gorm:"foreignKey:ID" json:"folders"`
}

func GetChildrenInFolder

func GetChildrenInFolder(parent *Folder) (*FolderContent, error)

func (*FolderContent) Length

func (f *FolderContent) Length() int

type Tree

type Tree struct {
	Root    *Folder `json:"root"`
	Files   []*File `json:"files"`
	Folders []*Tree `json:"folders"`
}

func GetChildrenRecursive

func GetChildrenRecursive(parent *Folder) (*Tree, error)

type User

type User struct {
	TelegramID int64  `gorm:"primaryKey" json:"userID"`
	ChatID     int64  `gorm:"non null" json:"-"`
	Username   string `gorm:"username" json:"username"`

	MasterKeySalt     string `gorm:"non null" json:"masterKeySalt"`
	AuthenticationKey []byte `gorm:"non null" json:"-"`

	ShareKeyPublic     string `gorm:"non null" json:"shareKeyPublic"`
	ShareKeyPrivateEnc string `gorm:"non null" json:"shareKeyPrivate"`
	ShareKeyNonce      string `gorm:"non null" json:"shareKeyNonce"`
}

func GetUserByID

func GetUserByID(userID int64) (*User, error)

func GetUserByName

func GetUserByName(username string) (*User, error)

Jump to

Keyboard shortcuts

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