Documentation
¶
Index ¶
- Constants
- Variables
- func CheckBgConfig(cfg *BgConfig, fillDefault bool) error
- func CheckFileInfo(info *FileInfo, fillDefault bool) error
- func CheckPreferences(prefers *Preferences, fillDefault bool) error
- func CheckQuota(quota *Quota) error
- func CheckSiteCfg(cfg *SiteConfig, fillDefault bool) error
- func CheckUser(user *User, fillDefault bool) error
- func ComparePreferences(p1, p2 *Preferences) bool
- func UploadNS(user string) string
- type BgConfig
- type ClientConfig
- type FileInfo
- type IConfigDB
- type IDB
- type IDBLockable
- type IDBQuickshare
- type IFileDB
- type IFileInfoStore
- type IFilesFunctions
- type ISharingDB
- type ISiteStore
- type IUploadDB
- type IUserDB
- type IUserStore
- type Preferences
- type Quota
- type SiteConfig
- type UploadInfo
- type User
- type UserCfg
Constants ¶
View Source
const ( UserSchemaNs = "UserSchemaNs" FileSchemaNs = "FileSchemaNs" UserIDsNs = "UserIDsNs" UsersNs = "UsersNs" RolesNs = "RolesNs" FileInfoNs = "FileInfoNs" KeyInitTime = "keyInitTime" AdminRole = "admin" UserRole = "user" VisitorRole = "visitor" BannedRole = "banned" VisitorID = uint64(1) VisitorName = "visitor" )
Variables ¶
View Source
var ( // users related errors ErrReachedLimit = errors.New("reached space limit") ErrUserNotFound = errors.New("user not found") ErrNegtiveUsedSpace = errors.New("used space can not be negative") ErrInvalidFileInfo = errors.New("invalid fileInfo") ErrInvalidUser = errors.New("invalid user") ErrInvalidQuota = errors.New("invalid quota") ErrInvalidPreferences = errors.New("invalid preferences") // files related errors ErrEmpty = errors.New("can not hash empty string") ErrFileInfoNotFound = errors.New("file info not found") ErrSharingNotFound = errors.New("sharing id not found") ErrConflicted = errors.New("conflict found in hashing") ErrVerNotFound = errors.New("file info schema version not found") // uploadings ErrGreaterThanSize = errors.New("uploaded is greater than file size") ErrUploadNotFound = errors.New("upload info not found") // site ErrConfigNotFound = errors.New("site config not found") ErrBucketNotFound = errors.New("bucket not found") ErrKeyNotFound = errors.New("key not found") ErrKeyExisting = errors.New("key is existing") ErrCreateExisting = errors.New("create upload info which already exists") ErrQuota = errors.New("quota limit reached") DefaultSiteName = "Quickshare" DefaultSiteDesc = "Quickshare" DefaultBgConfig = &BgConfig{ Url: "", Repeat: "repeat", Position: "top", Align: "fixed", BgColor: "", } DefaultAllowSetBg = false DefaultAutoTheme = true BgRepeatValues = map[string]bool{ "repeat-x": true, "repeat-y": true, "repeat": true, "space": true, "round": true, "no-repeat": true, } BgAlignValues = map[string]bool{ "scroll": true, "fixed": true, "local": true, } BgPositionValues = map[string]bool{ "top": true, "bottom": true, "left": true, "right": true, "center": true, } DefaultCSSURL = "" DefaultLanPackURL = "" DefaultLan = "en_US" DefaultTheme = "light" DefaultAvatar = "" DefaultEmail = "" DefaultSpaceLimit = int64(1024 * 1024 * 1024) // 1GB DefaultUploadSpeedLimit = 50 * 1024 * 1024 // 50MB DefaultDownloadSpeedLimit = 50 * 1024 * 1024 // 50MB VisitorUploadSpeedLimit = 10 * 1024 * 1024 // 10MB VisitorDownloadSpeedLimit = 10 * 1024 * 1024 // 10MB DefaultPreferences = Preferences{ Bg: DefaultBgConfig, CSSURL: DefaultCSSURL, LanPackURL: DefaultLanPackURL, Lan: DefaultLan, Theme: DefaultTheme, Avatar: DefaultAvatar, Email: DefaultEmail, } )
Functions ¶
func CheckBgConfig ¶ added in v0.8.1
func CheckFileInfo ¶ added in v0.8.1
TODO: auto trigger hash generating
func CheckPreferences ¶ added in v0.8.1
func CheckPreferences(prefers *Preferences, fillDefault bool) error
func CheckQuota ¶ added in v0.8.1
TODO: check upper and lower limit
func CheckSiteCfg ¶ added in v0.8.1
func CheckSiteCfg(cfg *SiteConfig, fillDefault bool) error
func ComparePreferences ¶ added in v0.7.1
func ComparePreferences(p1, p2 *Preferences) bool
Types ¶
type ClientConfig ¶ added in v0.8.1
type IConfigDB ¶ added in v0.10.1
type IConfigDB interface {
SetClientCfg(ctx context.Context, cfg *ClientConfig) error
GetCfg(ctx context.Context) (*SiteConfig, error)
}
type IDB ¶ added in v0.10.1
type IDB interface {
BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
Close() error
PingContext(ctx context.Context) error
PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
}
TODO: expose more APIs if needed
type IDBLockable ¶ added in v0.10.1
type IDBLockable interface {
Lock()
Unlock()
RLock()
RUnlock()
}
type IDBQuickshare ¶ added in v0.10.1
type IDBQuickshare interface {
IDBLockable
IUserDB
IFileDB
IUploadDB
ISharingDB
IConfigDB
}
type IFileDB ¶ added in v0.10.1
type IFileDB interface {
AddFileInfo(ctx context.Context, infoId, userId uint64, itemPath string, info *FileInfo) error
DelFileInfo(ctx context.Context, userId uint64, itemPath string) error
GetFileInfo(ctx context.Context, itemPath string) (*FileInfo, error)
SetSha1(ctx context.Context, itemPath, sign string) error
MoveFileInfo(ctx context.Context, userId uint64, oldPath, newPath string, isDir bool) error
ListFileInfos(ctx context.Context, itemPaths []string) (map[string]*FileInfo, error)
}
type IFileInfoStore ¶ added in v0.10.1
type IFileInfoStore interface {
AddSharing(ctx context.Context, dirPath string) error
DelSharing(ctx context.Context, dirPath string) error
GetSharing(ctx context.Context, dirPath string) (bool, bool)
ListSharings(ctx context.Context, prefix string) (map[string]string, error)
GetFileInfo(ctx context.Context, itemPath string) (*FileInfo, error)
SetFileInfo(ctx context.Context, itemPath string, info *FileInfo) error
DelFileInfo(ctx context.Context, itemPath string) error
ListFileInfos(ctx context.Context, itemPaths []string) (map[string]*FileInfo, error)
SetSha1(ctx context.Context, itemPath, sign string) error
GetSharingDir(ctx context.Context, hashID string) (string, error)
// upload info
AddUploadInfo(ctx context.Context, user, filePath, tmpPath string, fileSize int64) error
SetUploadInfo(ctx context.Context, user, filePath string, newUploaded int64) error
GetUploadInfo(ctx context.Context, user, filePath string) (string, int64, int64, error)
DelUploadInfo(ctx context.Context, user, filePath string) error
ListUploadInfo(ctx context.Context, user string) ([]*UploadInfo, error)
}
type IFilesFunctions ¶ added in v0.10.1
type IFilesFunctions interface {
IFileDB
IUploadDB
ISharingDB
}
type ISharingDB ¶ added in v0.10.1
type ISharingDB interface {
IsSharing(ctx context.Context, dirPath string) (bool, error)
GetSharingDir(ctx context.Context, hashID string) (string, error)
AddSharing(ctx context.Context, infoId, userId uint64, dirPath string) error
DelSharing(ctx context.Context, userId uint64, dirPath string) error
ListSharingsByLocation(ctx context.Context, location string) (map[string]string, error)
}
type ISiteStore ¶ added in v0.10.1
type ISiteStore interface {
SetClientCfg(ctx context.Context, cfg *ClientConfig) error
GetCfg(ctx context.Context) (*SiteConfig, error)
}
type IUploadDB ¶ added in v0.10.1
type IUploadDB interface {
AddUploadInfos(ctx context.Context, uploadId, userId uint64, tmpPath, filePath string, info *FileInfo) error
DelUploadingInfos(ctx context.Context, userId uint64, realPath string) error
MoveUploadingInfos(ctx context.Context, uploadId, userId uint64, uploadPath, itemPath string) error
SetUploadInfo(ctx context.Context, user uint64, filePath string, newUploaded int64) error
GetUploadInfo(ctx context.Context, userId uint64, filePath string) (string, int64, int64, error)
ListUploadInfos(ctx context.Context, user uint64) ([]*UploadInfo, error)
}
type IUserDB ¶ added in v0.10.1
type IUserDB interface {
AddUser(ctx context.Context, user *User) error
DelUser(ctx context.Context, id uint64) error
GetUser(ctx context.Context, id uint64) (*User, error)
GetUserByName(ctx context.Context, name string) (*User, error)
SetPwd(ctx context.Context, id uint64, pwd string) error
SetInfo(ctx context.Context, id uint64, user *User) error
SetPreferences(ctx context.Context, id uint64, prefers *Preferences) error
SetUsed(ctx context.Context, id uint64, incr bool, capacity int64) error
ResetUsed(ctx context.Context, id uint64, used int64) error
ListUsers(ctx context.Context) ([]*User, error)
ListUserIDs(ctx context.Context) (map[string]string, error)
AddRole(role string) error
DelRole(role string) error
ListRoles() (map[string]bool, error)
}
type IUserStore ¶ added in v0.10.1
type IUserStore interface {
Init(ctx context.Context, rootName, rootPwd string) error
IsInited() bool
AddUser(ctx context.Context, user *User) error
DelUser(ctx context.Context, id uint64) error
GetUser(ctx context.Context, id uint64) (*User, error)
GetUserByName(ctx context.Context, name string) (*User, error)
SetInfo(ctx context.Context, id uint64, user *User) error
SetUsed(ctx context.Context, id uint64, incr bool, capacity int64) error
ResetUsed(ctx context.Context, id uint64, used int64) error
SetPwd(ctx context.Context, id uint64, pwd string) error
SetPreferences(ctx context.Context, id uint64, settings *Preferences) error
ListUsers(context.Context) ([]*User, error)
ListUserIDs(context.Context) (map[string]string, error)
AddRole(role string) error
DelRole(role string) error
ListRoles() (map[string]bool, error)
}
type Preferences ¶
type Preferences struct {
Bg *BgConfig `json:"bg" yaml:"bg"`
CSSURL string `json:"cssURL" yaml:"cssURL"`
LanPackURL string `json:"lanPackURL" yaml:"lanPackURL"`
Lan string `json:"lan" yaml:"lan"`
Theme string `json:"theme" yaml:"theme"`
Avatar string `json:"avatar" yaml:"avatar"`
Email string `json:"email" yaml:"email"`
}
type SiteConfig ¶ added in v0.8.1
type SiteConfig struct {
ClientCfg *ClientConfig `json:"clientCfg" yaml:"clientCfg"`
}
type UploadInfo ¶
type User ¶
type User struct {
ID uint64 `json:"id,string" yaml:"id,string"`
Name string `json:"name" yaml:"name"`
Pwd string `json:"pwd" yaml:"pwd"`
Role string `json:"role" yaml:"role"`
UsedSpace int64 `json:"usedSpace,string" yaml:"usedSpace,string"`
Quota *Quota `json:"quota" yaml:"quota"`
Preferences *Preferences `json:"preferences" yaml:"preferences"`
}
Click to show internal directories.
Click to hide internal directories.