Documentation ¶
Index ¶
- Constants
- Variables
- func DeleteFiles(files []*File, uid uint) error
- func DeleteFolderByIDs(ids []uint) error
- func DeleteShareBySourceIDs(sources []uint, isDir bool) error
- func DeleteTagByID(id, uid uint) error
- func DeleteWebDAVAccountByID(id, uid uint)
- func GetIntSetting(key string, defaultVal int) int
- func GetSettingByName(name string) string
- func GetSettingByNameFromTx(tx *gorm.DB, name string) string
- func GetSettingByNameWithDefault(name, fallback string) string
- func GetSettingByNames(names ...string) map[string]string
- func GetSettingByType(types []string) map[string]string
- func GetSiteURL() *url.URL
- func Init()
- func InitSlaveDefaults()
- func IsTrueVal(val string) bool
- func UpdateWebDAVAccountByID(id, uid uint, updates map[string]interface{})
- type Aria2Option
- type Download
- type File
- func GetChildFilesOfFolders(folders *[]Folder) ([]File, error)
- func GetFilesByIDs(ids []uint, uid uint) ([]File, error)
- func GetFilesByIDsFromTX(tx *gorm.DB, ids []uint, uid uint) ([]File, error)
- func GetFilesByKeywords(uid uint, parents []uint, keywords ...interface{}) ([]File, error)
- func GetFilesByParentIDs(ids []uint, uid uint) ([]File, error)
- func GetFilesByUploadSession(sessionID string, uid uint) (*File, error)
- func GetUploadPlaceholderFiles(uid uint) []*File
- func RemoveFilesWithSoftLinks(files []File) ([]File, error)
- func (file *File) AfterFind() (err error)
- func (file *File) BeforeSave() (err error)
- func (file *File) CanCopy() bool
- func (file *File) Create() error
- func (file *File) CreateOrGetSourceLink() (*SourceLink, error)
- func (file *File) GetName() string
- func (file *File) GetPolicy() *Policy
- func (file *File) GetPosition() string
- func (file *File) GetSize() uint64
- func (file *File) IsDir() bool
- func (file *File) ModTime() time.Time
- func (file *File) PopChunkToFile(lastModified *time.Time, picInfo string) error
- func (file *File) Rename(new string) error
- func (file *File) ShouldLoadThumb() bool
- func (file *File) ThumbFile() string
- func (file *File) UpdateMetadata(data map[string]string) error
- func (file *File) UpdatePicInfo(value string) error
- func (file *File) UpdateSize(value uint64) error
- func (file *File) UpdateSourceName(value string) error
- type Folder
- func (folder *Folder) CopyFolderTo(folderID uint, dstFolder *Folder) (size uint64, err error)
- func (folder *Folder) Create() (uint, error)
- func (folder *Folder) GetChild(name string) (*Folder, error)
- func (folder *Folder) GetChildFile(name string) (*File, error)
- func (folder *Folder) GetChildFiles() ([]File, error)
- func (folder *Folder) GetChildFolder() ([]Folder, error)
- func (folder *Folder) GetName() string
- func (folder *Folder) GetPosition() string
- func (folder *Folder) GetSize() uint64
- func (folder *Folder) IsDir() bool
- func (folder *Folder) ModTime() time.Time
- func (folder *Folder) MoveFolderTo(dirs []uint, dstFolder *Folder) error
- func (folder *Folder) MoveOrCopyFileTo(files []uint, dstFolder *Folder, isCopy bool) (uint64, error)
- func (folder *Folder) Rename(new string) error
- func (folder *Folder) TraceRoot() error
- type Group
- type GroupOption
- type ModelType
- type Node
- type NodeStatus
- type Policy
- func (policy *Policy) AfterFind() (err error)
- func (policy *Policy) BeforeSave() (err error)
- func (policy *Policy) CanStructureBeListed() bool
- func (policy *Policy) ClearCache()
- func (policy *Policy) CouldProxyThumb() bool
- func (policy *Policy) GenerateFileName(uid uint, origin string) string
- func (policy *Policy) GeneratePath(uid uint, origin string) string
- func (policy *Policy) IsDirectlyPreview() bool
- func (policy *Policy) IsThumbGenerateNeeded() bool
- func (policy *Policy) IsTransitUpload(size uint64) bool
- func (policy *Policy) IsUploadPlaceholderWithSize() bool
- func (policy *Policy) SaveAndClearCache() error
- func (policy *Policy) SerializeOptions() (err error)
- func (policy *Policy) UpdateAccessKeyAndClearCache(s string) error
- type PolicyOption
- type Setting
- type Share
- func (share *Share) CanBeDownloadBy(user *User) error
- func (share *Share) Create() (uint, error)
- func (share *Share) Creator() *User
- func (share *Share) Delete() error
- func (share *Share) DownloadBy(user *User, c *gin.Context) error
- func (share *Share) Downloaded()
- func (share *Share) IsAvailable() bool
- func (share *Share) Source() interface{}
- func (share *Share) SourceFile() *File
- func (share *Share) SourceFolder() *Folder
- func (share *Share) Update(props map[string]interface{}) error
- func (share *Share) Viewed()
- func (share *Share) WasDownloadedBy(user *User, c *gin.Context) (exist bool)
- type SourceLink
- type Tag
- type Task
- type User
- func GetActiveUserByEmail(email string) (User, error)
- func GetActiveUserByID(ID interface{}) (User, error)
- func GetActiveUserByOpenID(openid string) (User, error)
- func GetUserByEmail(email string) (User, error)
- func GetUserByID(ID interface{}) (User, error)
- func NewAnonymousUser() *User
- func NewUser() User
- func (user *User) AfterCreate(tx *gorm.DB) (err error)
- func (user *User) AfterFind() (err error)
- func (user *User) BeforeSave() (err error)
- func (user *User) ChangeStorage(tx *gorm.DB, operator string, size uint64) error
- func (user *User) CheckPassword(password string) (bool, error)
- func (user *User) DeductionStorage(size uint64) bool
- func (user *User) GetPolicyID(prefer uint) uint
- func (user *User) GetRemainingCapacity() uint64
- func (user *User) IncreaseStorage(size uint64) bool
- func (user *User) IncreaseStorageWithoutCheck(size uint64)
- func (user *User) IsAnonymous() bool
- func (user *User) RegisterAuthn(credential *webauthn.Credential) error
- func (user *User) RemoveAuthn(id string)
- func (user *User) Root() (*Folder, error)
- func (user *User) SerializeOptions() (err error)
- func (user *User) SetPassword(password string) error
- func (user *User) SetStatus(status int)
- func (user *User) Update(val map[string]interface{}) error
- func (user *User) UpdateOptions() error
- func (user User) WebAuthnCredentials() []webauthn.Credential
- func (user User) WebAuthnDisplayName() string
- func (user User) WebAuthnID() []byte
- func (user User) WebAuthnIcon() string
- func (user User) WebAuthnName() string
- type UserOption
- type Webdav
Constants ¶
const ( ThumbStatusNotExist = "" ThumbStatusExist = "exist" ThumbStatusNotAvailable = "not_available" ThumbStatusMetadataKey = "thumb_status" ThumbSidecarMetadataKey = "thumb_sidecar" ChecksumMetadataKey = "webdav_checksum" )
Thumb related metadata
const ( // FileTagType 文件分类标签 FileTagType = iota // DirectoryLinkType 目录快捷方式标签 DirectoryLinkType )
const ( // Active 账户正常状态 Active = iota // NotActivicated 未激活 NotActivicated // Baned 被封禁 Baned // OveruseBaned 超额使用被封禁 OveruseBaned )
Variables ¶
var DB *gorm.DB
DB 数据库链接单例
Functions ¶
func DeleteShareBySourceIDs ¶
DeleteShareBySourceIDs 根据原始资源类型和ID删除文件
func DeleteWebDAVAccountByID ¶
func DeleteWebDAVAccountByID(id, uid uint)
DeleteWebDAVAccountByID 根据账户ID和UID删除账户
func GetIntSetting ¶
GetIntSetting 获取整形设置值,如果转换失败则返回默认值defaultVal
func GetSettingByNameFromTx ¶
GetSettingByNameFromTx 用 Name 获取设置值,使用事务
func GetSettingByNameWithDefault ¶
GetSettingByNameWithDefault 用 Name 获取设置值, 取不到时使用缺省值
func GetSettingByNames ¶
GetSettingByNames 用多个 Name 获取设置值
func GetSettingByType ¶
GetSettingByType 获取一个或多个分组的所有设置值
func InitSlaveDefaults ¶
func InitSlaveDefaults()
func UpdateWebDAVAccountByID ¶
UpdateWebDAVAccountByID 根据账户ID和UID更新账户
Types ¶
type Aria2Option ¶
type Aria2Option struct { // RPC 服务器地址 Server string `json:"server,omitempty"` // RPC 密钥 Token string `json:"token,omitempty"` // 临时下载目录 TempPath string `json:"temp_path,omitempty"` // 附加下载配置 Options string `json:"options,omitempty"` // 下载监控间隔 Interval int `json:"interval,omitempty"` // RPC API 请求超时 Timeout int `json:"timeout,omitempty"` }
Aria2Option 非公有的Aria2配置属性
type Download ¶
type Download struct { gorm.Model Status int // 任务状态 Type int // 任务类型 Source string `gorm:"type:text"` // 文件下载地址 TotalSize uint64 // 文件大小 DownloadedSize uint64 // 文件大小 GID string `gorm:"size:32,index:gid"` // 任务ID Speed int // 下载速度 Parent string `gorm:"type:text"` // 存储目录 Attrs string `gorm:"size:4294967295"` // 任务状态属性 Error string `gorm:"type:text"` // 错误描述 Dst string `gorm:"type:text"` // 用户文件系统存储父目录路径 UserID uint // 发起者UID TaskID uint // 对应的转存任务ID NodeID uint // 处理任务的节点ID // 关联模型 User *User `gorm:"PRELOAD:false,association_autoupdate:false"` // 数据库忽略字段 StatusInfo rpc.StatusInfo `gorm:"-"` Task *Task `gorm:"-"` NodeName string `gorm:"-"` }
Download 离线下载队列模型
func GetDownloadByGid ¶
GetDownloadByGid 根据GID和用户ID查找下载
func GetDownloadsByStatus ¶
GetDownloadsByStatus 根据状态检索下载
func GetDownloadsByStatusAndUser ¶
GetDownloadsByStatusAndUser 根据状态检索和用户ID下载 page 为 0 表示列出所有,非零时分页
func (*Download) BeforeSave ¶
BeforeSave Save下载任务前的钩子
type File ¶
type File struct { // 表字段 gorm.Model Name string `gorm:"unique_index:idx_only_one"` SourceName string `gorm:"type:text"` UserID uint `gorm:"index:user_id;unique_index:idx_only_one"` Size uint64 PicInfo string FolderID uint `gorm:"index:folder_id;unique_index:idx_only_one"` PolicyID uint UploadSessionID *string `gorm:"index:session_id;unique_index:session_only_one"` Metadata string `gorm:"type:text"` // 关联模型 Policy Policy `gorm:"PRELOAD:false,association_autoupdate:false"` // 数据库忽略字段 Position string `gorm:"-"` MetadataSerialized map[string]string `gorm:"-"` }
File 文件
func GetChildFilesOfFolders ¶
GetChildFilesOfFolders 批量检索目录子文件
func GetFilesByIDs ¶
GetFilesByIDs 根据文件ID批量获取文件, UID为0表示忽略用户,只根据文件ID检索
func GetFilesByIDsFromTX ¶
func GetFilesByKeywords ¶
GetFilesByKeywords 根据关键字搜索文件, UID为0表示忽略用户,只根据文件ID检索. 如果 parents 非空, 则只限制在 parent 包含的目录下搜索
func GetFilesByParentIDs ¶
GetFilesByParentIDs 根据父目录ID查找文件
func GetFilesByUploadSession ¶
GetFilesByUploadSession 查找上传会话对应的文件
func GetUploadPlaceholderFiles ¶
GetUploadPlaceholderFiles 获取所有上传占位文件 UID为0表示忽略用户
func RemoveFilesWithSoftLinks ¶
RemoveFilesWithSoftLinks 去除给定的文件列表中有软链接的文件
func (*File) CreateOrGetSourceLink ¶
func (file *File) CreateOrGetSourceLink() (*SourceLink, error)
CreateOrGetSourceLink creates a SourceLink model. If the given model exists, the existing model will be returned.
func (*File) GetPosition ¶
func (*File) PopChunkToFile ¶
func (*File) ShouldLoadThumb ¶
ShouldLoadThumb returns if file explorer should try to load thumbnail for this file. `True` does not guarantee the load request will success in next step, but the client should try to load and fallback to default placeholder in case error returned.
func (*File) UpdateMetadata ¶
UpdateMetadata 新增或修改文件的元信息
func (*File) UpdatePicInfo ¶
UpdatePicInfo 更新文件的图像信息
func (*File) UpdateSize ¶
UpdateSize 更新文件的大小信息 TODO: 全局锁
func (*File) UpdateSourceName ¶
UpdateSourceName 更新文件的源文件名
type Folder ¶
type Folder struct { // 表字段 gorm.Model Name string `gorm:"unique_index:idx_only_one_name"` ParentID *uint `gorm:"index:parent_id;unique_index:idx_only_one_name"` OwnerID uint `gorm:"index:owner_id"` // 数据库忽略字段 Position string `gorm:"-"` WebdavDstName string `gorm:"-"` }
Folder 目录
func GetFoldersByIDs ¶
GetFoldersByIDs 根据ID和用户查找所有目录
func GetRecursiveChildFolder ¶
GetRecursiveChildFolder 查找所有递归子目录,包括自身
func (*Folder) CopyFolderTo ¶
CopyFolderTo 将此目录及其子目录及文件递归复制至dstFolder 返回此操作新增的容量
func (*Folder) GetChildFile ¶
GetChildFile 查找目录下名为name的子文件
func (*Folder) GetChildFiles ¶
GetChildFiles 查找目录下子文件
func (*Folder) GetChildFolder ¶
GetChildFolder 查找子目录
func (*Folder) GetPosition ¶
func (*Folder) MoveFolderTo ¶
MoveFolderTo 将folder目录下的dirs子目录复制或移动到dstFolder, 返回此过程中增加的容量
type Group ¶
type Group struct { gorm.Model Name string Policies string MaxStorage uint64 WebDAVEnabled bool SpeedLimit int Options string `json:"-" gorm:"size:4294967295"` // 数据库忽略字段 PolicyList []uint `gorm:"-"` OptionsSerialized GroupOption `gorm:"-"` }
Group 用户组模型
func (*Group) SerializePolicyList ¶
SerializePolicyList 将序列后的可选策略列表、配置写入数据库字段 TODO 完善测试
type GroupOption ¶
type GroupOption struct { ArchiveDownload bool `json:"archive_download,omitempty"` // 打包下载 ArchiveTask bool `json:"archive_task,omitempty"` // 在线压缩 CompressSize uint64 `json:"compress_size,omitempty"` // 可压缩大小 DecompressSize uint64 `json:"decompress_size,omitempty"` OneTimeDownload bool `json:"one_time_download,omitempty"` Aria2 bool `json:"aria2,omitempty"` // 离线下载 Aria2Options map[string]interface{} `json:"aria2_options,omitempty"` // 离线下载用户组配置 SourceBatchSize int `json:"source_batch,omitempty"` RedirectedSource bool `json:"redirected_source,omitempty"` Aria2BatchSize int `json:"aria2_batch,omitempty"` AdvanceDelete bool `json:"advance_delete,omitempty"` WebDAVProxy bool `json:"webdav_proxy,omitempty"` }
GroupOption 用户组其他配置
type Node ¶
type Node struct { gorm.Model Status NodeStatus // 节点状态 Name string // 节点别名 Type ModelType // 节点状态 Server string // 服务器地址 SlaveKey string `gorm:"type:text"` // 主->从 通信密钥 MasterKey string `gorm:"type:text"` // 从->主 通信密钥 Aria2Enabled bool // 是否支持用作离线下载节点 Aria2Options string `gorm:"type:text"` // 离线下载配置 Rank int // 负载均衡权重 // 数据库忽略字段 Aria2OptionsSerialized Aria2Option `gorm:"-"` }
Node 从机节点信息模型
func GetNodesByStatus ¶
func GetNodesByStatus(status ...NodeStatus) ([]Node, error)
GetNodesByStatus 根据给定状态获取节点
type Policy ¶
type Policy struct { // 表字段 gorm.Model Name string Type string Server string BucketName string IsPrivate bool BaseURL string AccessKey string `gorm:"type:text"` SecretKey string `gorm:"type:text"` MaxSize uint64 AutoRename bool DirNameRule string FileNameRule string IsOriginLinkEnable bool Options string `gorm:"type:text"` // 数据库忽略字段 OptionsSerialized PolicyOption `gorm:"-"` MasterID string `gorm:"-"` }
Policy 存储策略
func (*Policy) CanStructureBeListed ¶
CanStructureBeListed 返回存储策略是否能被前台列物理目录
func (*Policy) CouldProxyThumb ¶
CouldProxyThumb return if proxy thumbs is allowed for this policy.
func (*Policy) GenerateFileName ¶
GenerateFileName 生成存储文件名
func (*Policy) GeneratePath ¶
GeneratePath 生成存储文件的路径
func (*Policy) IsDirectlyPreview ¶
IsDirectlyPreview 返回此策略下文件是否可以直接预览(不需要重定向)
func (*Policy) IsThumbGenerateNeeded ¶
IsThumbGenerateNeeded 返回此策略是否需要在上传后生成缩略图
func (*Policy) IsTransitUpload ¶
IsTransitUpload 返回此策略上传给定size文件时是否需要服务端中转
func (*Policy) IsUploadPlaceholderWithSize ¶
IsUploadPlaceholderWithSize 返回此策略创建上传会话时是否需要预留空间
func (*Policy) SaveAndClearCache ¶
SaveAndClearCache 更新并清理缓存
func (*Policy) SerializeOptions ¶
SerializeOptions 将序列后的Option写入到数据库字段
func (*Policy) UpdateAccessKeyAndClearCache ¶
SaveAndClearCache 更新并清理缓存
type PolicyOption ¶
type PolicyOption struct { // Upyun访问Token Token string `json:"token"` // 允许的文件扩展名 FileType []string `json:"file_type"` // MimeType MimeType string `json:"mimetype"` // OauthRedirect Oauth 重定向地址 OauthRedirect string `json:"od_redirect,omitempty"` // OdProxy Onedrive 反代地址 OdProxy string `json:"od_proxy,omitempty"` // OdDriver OneDrive 驱动器定位符 OdDriver string `json:"od_driver,omitempty"` // Region 区域代码 Region string `json:"region,omitempty"` // ServerSideEndpoint 服务端请求使用的 Endpoint,为空时使用 Policy.Server 字段 ServerSideEndpoint string `json:"server_side_endpoint,omitempty"` // 分片上传的分片大小 ChunkSize uint64 `json:"chunk_size,omitempty"` // 分片上传时是否需要预留空间 PlaceholderWithSize bool `json:"placeholder_with_size,omitempty"` // 每秒对存储端的 API 请求上限 TPSLimit float64 `json:"tps_limit,omitempty"` // 每秒 API 请求爆发上限 TPSLimitBurst int `json:"tps_limit_burst,omitempty"` // Set this to `true` to force the request to use path-style addressing, // i.e., `http://s3.amazonaws.com/BUCKET/KEY ` S3ForcePathStyle bool `json:"s3_path_style"` // File extensions that support thumbnail generation using native policy API. ThumbExts []string `json:"thumb_exts,omitempty"` }
PolicyOption 非公有的存储策略属性
type Setting ¶
type Setting struct { gorm.Model Type string `gorm:"not null"` Name string `gorm:"unique;not null;index:setting_key"` Value string `gorm:"size:65535"` }
Setting 系统设置模型
type Share ¶
type Share struct { // 数据库忽略字段 }
Share 分享模型
func ListShares ¶
ListShares 列出UID下的分享
func SearchShares ¶
SearchShares 根据关键字搜索分享
func (*Share) CanBeDownloadBy ¶
CanBeDownloadBy 返回此分享是否可以被给定用户下载
func (*Share) DownloadBy ¶
DownloadBy 增加下载次数,匿名用户不会缓存
type SourceLink ¶
type SourceLink struct { gorm.Model FileID uint // corresponding file ID Name string // name of the file while creating the source link, for annotation Downloads int // 下载数 // 关联模型 File File `gorm:"save_associations:false:false"` }
SourceLink represent a shared file source link
func GetSourceLinkByID ¶
func GetSourceLinkByID(id interface{}) (*SourceLink, error)
GetTasksByID queries source link based on ID
func (*SourceLink) Link ¶
func (s *SourceLink) Link() (string, error)
Link gets the URL of a SourceLink
type Tag ¶
type Tag struct { gorm.Model Name string // 标签名 Icon string // 图标标识 Color string // 图标颜色 Type int // 标签类型(文件分类/目录直达) Expression string `gorm:"type:text"` // 搜索表表达式/直达路径 UserID uint // 创建者ID }
Tag 用户自定义标签
type Task ¶
type Task struct { gorm.Model Status int // 任务状态 Type int // 任务类型 UserID uint // 发起者UID,0表示为系统发起 Progress int // 进度 Error string `gorm:"type:text"` // 错误信息 Props string `gorm:"type:text"` // 任务属性 }
Task 任务模型
type User ¶
type User struct { // 表字段 gorm.Model Email string `gorm:"type:varchar(100);unique_index"` Nick string `gorm:"size:50"` Password string `json:"-"` Status int GroupID uint Storage uint64 TwoFactor string Avatar string Options string `json:"-" gorm:"size:4294967295"` Authn string `gorm:"size:4294967295"` // 关联模型 Group Group `gorm:"save_associations:false:false"` Policy Policy `gorm:"PRELOAD:false,association_autoupdate:false"` // 数据库忽略字段 OptionsSerialized UserOption `gorm:"-"` }
User 用户模型
func GetActiveUserByEmail ¶
GetActiveUserByEmail 用Email获取可登录用户
func GetActiveUserByID ¶
GetActiveUserByID 用ID获取可登录用户
func GetActiveUserByOpenID ¶
GetActiveUserByOpenID 用OpenID获取可登录用户
func (*User) AfterCreate ¶
AfterCreate 创建用户后的钩子
func (*User) ChangeStorage ¶
ChangeStorage 更新用户容量
func (*User) CheckPassword ¶
CheckPassword 根据明文校验密码
func (*User) DeductionStorage ¶
DeductionStorage 减少用户已用容量
func (*User) GetPolicyID ¶
GetPolicyID 获取用户当前的存储策略ID
func (*User) GetRemainingCapacity ¶
GetRemainingCapacity 获取剩余配额
func (*User) IncreaseStorage ¶
IncreaseStorage 检查并增加用户已用容量
func (*User) IncreaseStorageWithoutCheck ¶
IncreaseStorageWithoutCheck 忽略可用容量,增加用户已用容量
func (*User) RegisterAuthn ¶
func (user *User) RegisterAuthn(credential *webauthn.Credential) error
RegisterAuthn 添加新的验证器
func (*User) SerializeOptions ¶
SerializeOptions 将序列后的Option写入到数据库字段
func (*User) SetPassword ¶
SetPassword 根据给定明文设定 User 的 Password 字段
func (User) WebAuthnCredentials ¶
func (user User) WebAuthnCredentials() []webauthn.Credential
WebAuthnCredentials 获得已注册的验证器凭证
func (User) WebAuthnDisplayName ¶
WebAuthnDisplayName 获得用于展示的用户名
type UserOption ¶
type UserOption struct { ProfileOff bool `json:"profile_off,omitempty"` PreferredTheme string `json:"preferred_theme,omitempty"` }
UserOption 用户个性化配置字段
type Webdav ¶
type Webdav struct { gorm.Model Name string // 应用名称 Password string `gorm:"unique_index:password_only_on"` // 应用密码 UserID uint `gorm:"unique_index:password_only_on"` // 用户ID Root string `gorm:"type:text"` // 根目录 Readonly bool `gorm:"type:bool"` // 是否只读 UseProxy bool `gorm:"type:bool"` // 是否进行反代 }
Webdav 应用账户
func GetWebdavByPassword ¶
GetWebdavByPassword 根据密码和用户查找Webdav应用