model

package
v1.3.7 Latest Latest
Warning

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

Go to latest
Published: May 24, 2024 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PackOrderType 容量包订单
	PackOrderType = iota
	// GroupOrderType 用户组订单
	GroupOrderType
	// ScoreOrderType 积分充值订单
	ScoreOrderType
)
View Source
const (
	// OrderUnpaid 未支付
	OrderUnpaid = iota
	// OrderPaid 已支付
	OrderPaid
	// OrderCanceled 已取消
	OrderCanceled
)
View Source
const (
	// FileTagType 文件分类标签
	FileTagType = iota
	// DirectoryLinkType 目录快捷方式标签
	DirectoryLinkType
)
View Source
const (
	// Active 账户正常状态
	Active = iota
	// NotActivicated 未激活
	NotActivicated
	// Baned 被封禁
	Baned
	// OveruseBaned 超额使用被封禁
	OveruseBaned
)

Variables

View Source
var DB *gorm.DB

DB 数据库链接单例

Functions

func CopyTeamsMemberToFolderId

func CopyTeamsMemberToFolderId(folder Folder, parentTeamsMembers []TeamsFolderMember)

func DeleteFiles

func DeleteFiles(files []*File, uid uint) error

DeleteFiles 批量删除文件记录并归还容量

func DeleteFolderByIDs

func DeleteFolderByIDs(ids []uint) error

DeleteFolderByIDs 根据给定ID批量删除目录记录

func DeleteShareBySourceIDs

func DeleteShareBySourceIDs(sources []uint, isDir bool) error

DeleteShareBySourceIDs 根据原始资源类型和ID删除文件

func DeleteTagByID

func DeleteTagByID(id, uid uint) error

DeleteTagByID 根据给定ID和用户ID删除标签

func DeleteTeamsFoloderBySourceIDs

func DeleteTeamsFoloderBySourceIDs(sources []uint, isDir bool) error

DeleteShareBySourceIDs 根据原始资源类型和ID删除文件

func DeleteWebDAVAccountByID

func DeleteWebDAVAccountByID(id, uid uint)

DeleteWebDAVAccountByID 根据账户ID和UID删除账户

func GetIntSetting

func GetIntSetting(key string, defaultVal int) int

GetIntSetting 获取整形设置值,如果转换失败则返回默认值defaultVal

func GetSettingByName

func GetSettingByName(name string) string

GetSettingByName 用 Name 获取设置值

func GetSettingByNameFromTx

func GetSettingByNameFromTx(tx *gorm.DB, name string) string

GetSettingByNameFromTx 用 Name 获取设置值,使用事务

func GetSettingByNameWithDefault

func GetSettingByNameWithDefault(name, fallback string) string

GetSettingByNameWithDefault 用 Name 获取设置值, 取不到时使用缺省值

func GetSettingByNames

func GetSettingByNames(names ...string) map[string]string

GetSettingByNames 用多个 Name 获取设置值

func GetSettingByType

func GetSettingByType(types []string) map[string]string

GetSettingByType 获取一个或多个分组的所有设置值

func GetSiteURL

func GetSiteURL() *url.URL

GetSiteURL 获取站点地址

func GetUserTeamsRootFolder

func GetUserTeamsRootFolder(userId uint) (sourceIds []uint)

func Init

func Init()

Init 初始化 MySQL 链接

func IsTrueVal

func IsTrueVal(val string) bool

IsTrueVal 返回设置的值是否为真

func OurMD5

func OurMD5(usr string, pwd string, salt string) string

MD5加密函数 @str string 需要进行加密的字符串

func TransferTeamsFoldersToUsers

func TransferTeamsFoldersToUsers(dirs []uint, folderIteams []FolderItem, UserItems []TeamsFolderMember) (err error)

func UserTeamsFolderIsRoot

func UserTeamsFolderIsRoot(sourceMembers []TeamsFolderMember, sourceFolder TeamsFolderMember) (IsRoot bool)

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:"-"`
}

Download 离线下载队列模型

func GetDownloadByGid

func GetDownloadByGid(gid string, uid uint) (*Download, error)

GetDownloadByGid 根据GID和用户ID查找下载

func GetDownloadsByStatus

func GetDownloadsByStatus(status ...int) []Download

GetDownloadsByStatus 根据状态检索下载

func GetDownloadsByStatusAndUser

func GetDownloadsByStatusAndUser(page, uid uint, status ...int) []Download

GetDownloadsByStatusAndUser 根据状态检索和用户ID下载 page 为 0 表示列出所有,非零时分页

func (*Download) AfterFind

func (task *Download) AfterFind() (err error)

AfterFind 找到下载任务后的钩子,处理Status结构

func (*Download) BeforeSave

func (task *Download) BeforeSave() (err error)

BeforeSave Save下载任务前的钩子

func (*Download) Create

func (task *Download) Create() (uint, error)

Create 创建离线下载记录

func (*Download) Delete

func (download *Download) Delete() error

Delete 删除离线下载记录

func (*Download) GetNodeID

func (task *Download) GetNodeID() uint

GetNodeID 返回任务所属节点ID

func (*Download) GetOwner

func (task *Download) GetOwner() *User

GetOwner 获取下载任务所属用户

func (*Download) Save

func (task *Download) Save() error

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

func GetChildFilesOfFolders(folders *[]Folder) ([]File, error)

GetChildFilesOfFolders 批量检索目录子文件

func GetFilesByIDs

func GetFilesByIDs(ids []uint, uid uint) ([]File, error)

GetFilesByIDs 根据文件ID批量获取文件, UID为0表示忽略用户,只根据文件ID检索

func GetFilesByIDsFromTX

func GetFilesByIDsFromTX(tx *gorm.DB, ids []uint, uid uint) ([]File, error)

func GetFilesByKeywords

func GetFilesByKeywords(uid uint, parents []uint, keywords ...interface{}) ([]File, error)

GetFilesByKeywords 根据关键字搜索文件, UID为0表示忽略用户,只根据文件ID检索. 如果 parents 非空, 则只限制在 parent 包含的目录下搜索

func GetFilesByParentIDs

func GetFilesByParentIDs(ids []uint, uid uint) ([]File, error)

GetFilesByParentIDs 根据父目录ID查找文件

func GetFilesByUploadSession

func GetFilesByUploadSession(sessionID string, uid uint) (*File, error)

GetFilesByUploadSession 查找上传会话对应的文件

func GetUploadPlaceholderFiles

func GetUploadPlaceholderFiles(uid uint) []*File

GetUploadPlaceholderFiles 获取所有上传占位文件 UID为0表示忽略用户

func RemoveFilesWithSoftLinks(files []File) ([]File, error)

RemoveFilesWithSoftLinks 去除给定的文件列表中有软链接的文件

func (*File) AfterFind

func (file *File) AfterFind() (err error)

AfterFind 找到文件后的钩子

func (*File) BeforeSave

func (file *File) BeforeSave() (err error)

BeforeSave Save策略前的钩子

func (*File) CanCopy

func (file *File) CanCopy() bool

CanCopy 返回文件是否可被复制

func (*File) Close

func (file *File) Close() error

Close 实现io.Closer

func (*File) Create

func (file *File) Create() error

Create 创建文件记录

func (*File) GetName

func (file *File) GetName() string

func (*File) GetPolicy

func (file *File) GetPolicy() *Policy

GetPolicy 获取文件所属策略

func (*File) GetPosition

func (file *File) GetPosition() string

func (*File) GetSize

func (file *File) GetSize() uint64

func (*File) IsDir

func (file *File) IsDir() bool

func (*File) ModTime

func (file *File) ModTime() time.Time

func (*File) PopChunkToFile

func (file *File) PopChunkToFile(lastModified *time.Time, picInfo string) error

func (*File) Read

func (file *File) Read(p []byte) (n int, err error)

Read 实现 io.Reader

func (*File) Relocate

func (file *File) Relocate(src string, policyID uint) error

Relocate 更新文件的物理指向

func (*File) Rename

func (file *File) Rename(new string) error

Rename 重命名文件

func (*File) Seek

func (file *File) Seek(offset int64, whence int) (int64, error)

Seeker 实现io.Seeker

func (*File) Seekable

func (file *File) Seekable() bool

func (*File) SetModel

func (file *File) SetModel(newFile interface{})

func (*File) SetSize

func (file *File) SetSize(size uint64)

func (*File) UpdatePicInfo

func (file *File) UpdatePicInfo(value string) error

UpdatePicInfo 更新文件的图像信息

func (*File) UpdateSize

func (file *File) UpdateSize(value uint64) error

UpdateSize 更新文件的大小信息 TODO: 全局锁

func (*File) UpdateSourceName

func (file *File) UpdateSourceName(value string) error

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"`
	PolicyID uint   // Webdav下挂载的存储策略ID
	Lock     uint
	// 数据库忽略字段
	Position        string              `gorm:"-"`
	InheritPolicyID uint                `gorm:"-"` //  从父目录继承而来的policy id,默认值则使用自身的的PolicyID
	TeamsMembers    []TeamsFolderMember `sql:"-" gorm:"-"`
}

Folder 目录

func GetChildFolderById

func GetChildFolderById(id uint) Folder

func GetFolderByHashID

func GetFolderByHashID(hashID string) *Folder

GetShareByHashID 根据HashID查找分享

func GetFolderById

func GetFolderById(id uint) Folder

func GetFoldersByIDs

func GetFoldersByIDs(ids []uint, uid uint) ([]Folder, error)

GetFoldersByIDs 根据ID和用户查找所有目录

func GetMountedFolders

func GetMountedFolders(uid uint) []Folder

GetMountedFolders 列出已挂载存储策略的目录

func GetParentFolderById

func GetParentFolderById(id uint) Folder

func GetRecursiveChildFolder

func GetRecursiveChildFolder(dirs []uint, uid uint, includeSelf bool) ([]Folder, error)

GetRecursiveChildFolder 查找所有递归子目录,包括自身

func GetSameNameRootFolderByUserId

func GetSameNameRootFolderByUserId(userId, parentId uint, name string) Folder

func (*Folder) CopyFolderTo

func (folder *Folder) CopyFolderTo(folderID uint, dstFolder *Folder) (size uint64, err error)

CopyFolderTo 将此目录及其子目录及文件递归复制至dstFolder 返回此操作新增的容量

func (*Folder) Create

func (folder *Folder) Create() (uint, error)

Create 创建目录

func (*Folder) GetChild

func (folder *Folder) GetChild(name string) (*Folder, error)

GetChild 返回folder下名为name的子目录,不存在则返回错误

func (*Folder) GetChildFile

func (folder *Folder) GetChildFile(name string) (*File, error)

GetChildFile 查找目录下名为name的子文件

func (*Folder) GetChildFiles

func (folder *Folder) GetChildFiles() ([]File, error)

GetChildFiles 查找目录下子文件

func (*Folder) GetChildFolder

func (folder *Folder) GetChildFolder(uid uint) ([]Folder, error)

GetChildFolder 查找子目录

func (*Folder) GetName

func (folder *Folder) GetName() string

func (*Folder) GetPosition

func (folder *Folder) GetPosition() string

func (*Folder) GetSize

func (folder *Folder) GetSize() uint64

func (*Folder) IsDir

func (folder *Folder) IsDir() bool

func (*Folder) ModTime

func (folder *Folder) ModTime() time.Time

func (*Folder) Mount

func (folder *Folder) Mount(new uint) error

Mount 目录挂载

func (*Folder) MoveFolderTo

func (folder *Folder) MoveFolderTo(dirs []uint, dstFolder *Folder) error

MoveFolderTo 将folder目录下的dirs子目录复制或移动到dstFolder, 返回此过程中增加的容量

func (*Folder) MoveOrCopyFileTo

func (folder *Folder) MoveOrCopyFileTo(files []uint, dstFolder *Folder, isCopy bool) (uint64, error)

MoveOrCopyFileTo 将此目录下的files移动或复制至dstFolder, 返回此操作新增的容量

func (*Folder) Rename

func (folder *Folder) Rename(new string) error

Rename 重命名目录

func (*Folder) TraceRoot

func (folder *Folder) TraceRoot() error

TraceRoot 向上递归查找父目录

func (*Folder) TraceTeamsRoot

func (folder *Folder) TraceTeamsRoot() error

type FolderItem

type FolderItem struct {
	Folder Folder `json:"folder"`
	Dir    uint   `json:"dir"`
}

ItemService 处理多文件/目录相关服务

type Group

type Group struct {
	gorm.Model
	Name          string
	Policies      string
	MaxStorage    uint64
	ShareEnabled  bool
	WebDAVEnabled bool
	SpeedLimit    int
	Options       string `json:"-" gorm:"size:4294967295"`

	// 数据库忽略字段
	PolicyList        []uint      `gorm:"-"`
	OptionsSerialized GroupOption `gorm:"-"`
}

Group 用户组模型

func GetGroupByID

func GetGroupByID(ID interface{}) (Group, error)

GetGroupByID 用ID获取用户组

func (*Group) AfterFind

func (group *Group) AfterFind() (err error)

AfterFind 找到用户组后的钩子,处理Policy列表

func (*Group) BeforeSave

func (group *Group) BeforeSave() (err error)

BeforeSave Save用户前的钩子

func (*Group) SerializePolicyList

func (group *Group) SerializePolicyList() (err error)

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"`
	ShareDownload   bool                   `json:"share_download,omitempty"`
	ShareFree       bool                   `json:"share_free,omitempty"`
	Aria2           bool                   `json:"aria2,omitempty"`         // 离线下载
	Aria2Options    map[string]interface{} `json:"aria2_options,omitempty"` // 离线下载用户组配置
	Relocate        bool                   `json:"relocate,omitempty"`      // 转移文件
	SourceBatchSize int                    `json:"source_batch,omitempty"`
	Aria2BatchSize  int                    `json:"aria2_batch,omitempty"`
}

GroupOption 用户组其他配置

type ModelType

type ModelType int
const (
	SlaveNodeType ModelType = iota
	MasterNodeType
)

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 GetNodeByID

func GetNodeByID(ID interface{}) (Node, error)

GetNodeByID 用ID获取节点

func GetNodesByStatus

func GetNodesByStatus(status ...NodeStatus) ([]Node, error)

GetNodesByStatus 根据给定状态获取节点

func (*Node) AfterFind

func (node *Node) AfterFind() (err error)

AfterFind 找到节点后的钩子

func (*Node) BeforeSave

func (node *Node) BeforeSave() (err error)

BeforeSave Save策略前的钩子

func (*Node) SetStatus

func (node *Node) SetStatus(status NodeStatus) error

SetStatus 设置节点启用状态

type NodeStatus

type NodeStatus int
const (
	NodeActive NodeStatus = iota
	NodeSuspend
)

type Order

type Order struct {
	gorm.Model
	UserID    uint   // 创建者ID
	OrderNo   string `gorm:"index:order_number"` // 商户自定义订单编号
	Type      int    // 订单类型
	Method    string // 支付类型
	ProductID int64  // 商品ID
	Num       int    // 商品数量
	Name      string // 订单标题
	Price     int    // 商品单价
	Status    int    // 订单状态
}

Order 交易订单

func GetOrderByNo

func GetOrderByNo(id string) (*Order, error)

GetOrderByNo 根据商户订单号查询订单

func (*Order) Create

func (order *Order) Create() (uint, error)

Create 创建订单记录

func (*Order) UpdateStatus

func (order *Order) UpdateStatus(status int)

UpdateStatus 更新订单状态

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 GetPolicyByID

func GetPolicyByID(ID interface{}) (Policy, error)

GetPolicyByID 用ID获取存储策略

func (*Policy) AfterFind

func (policy *Policy) AfterFind() (err error)

AfterFind 找到存储策略后的钩子

func (*Policy) BeforeSave

func (policy *Policy) BeforeSave() (err error)

BeforeSave Save策略前的钩子

func (*Policy) CanStructureBeListed

func (policy *Policy) CanStructureBeListed() bool

CanStructureBeListed 返回存储策略是否能被前台列物理目录

func (*Policy) ClearCache

func (policy *Policy) ClearCache()

ClearCache 清空policy缓存

func (*Policy) GenerateFileName

func (policy *Policy) GenerateFileName(uid uint, origin string) string

GenerateFileName 生成存储文件名

func (*Policy) GeneratePath

func (policy *Policy) GeneratePath(uid uint, origin string) string

GeneratePath 生成存储文件的路径

func (*Policy) IsDirectlyPreview

func (policy *Policy) IsDirectlyPreview() bool

IsDirectlyPreview 返回此策略下文件是否可以直接预览(不需要重定向)

func (*Policy) IsThumbExist

func (policy *Policy) IsThumbExist(name string) bool

IsThumbExist 给定文件名,返回此存储策略下是否可能存在缩略图

func (*Policy) IsThumbGenerateNeeded

func (policy *Policy) IsThumbGenerateNeeded() bool

IsThumbGenerateNeeded 返回此策略是否需要在上传后生成缩略图

func (*Policy) IsTransitUpload

func (policy *Policy) IsTransitUpload(size uint64) bool

IsTransitUpload 返回此策略上传给定size文件时是否需要服务端中转

func (*Policy) IsUploadPlaceholderWithSize

func (policy *Policy) IsUploadPlaceholderWithSize() bool

IsUploadPlaceholderWithSize 返回此策略创建上传会话时是否需要预留空间

func (*Policy) SaveAndClearCache

func (policy *Policy) SaveAndClearCache() error

SaveAndClearCache 更新并清理缓存

func (*Policy) SerializeOptions

func (policy *Policy) SerializeOptions() (err error)

SerializeOptions 将序列后的Option写入到数据库字段

func (*Policy) UpdateAccessKeyAndClearCache

func (policy *Policy) UpdateAccessKeyAndClearCache(s string) error

SaveAndClearCache 更新并清理缓存

type PolicyOption

type PolicyOption struct {
	// Upyun访问Token
	Token string `json:"token"`
	// 允许的文件扩展名
	FileType []string `json:"file_type"`
	// MimeType
	MimeType string `json:"mimetype"`
	// OdRedirect Onedrive 重定向地址
	OdRedirect 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"`
	// url
	CallbackSer string `json:"callback_ser,omitempty"`
	// 下载地址
	DownloadUrl string `json:"download_url,omitempty"`
}

PolicyOption 非公有的存储策略属性

type Redeem

type Redeem struct {
	gorm.Model
	Type      int    // 订单类型
	ProductID int64  // 商品ID
	Num       int    // 商品数量
	Code      string `gorm:"size:64,index:redeem_code"` // 兑换码
	Used      bool   // 是否已被使用
}

Redeem 兑换码

func GetAvailableRedeem

func GetAvailableRedeem(code string) (*Redeem, error)

GetAvailableRedeem 根据code查找可用兑换码

func (*Redeem) Use

func (redeem *Redeem) Use()

Use 设定为已使用状态

type Report

type Report struct {
	gorm.Model
	ShareID     uint   `gorm:"index:share_id"` // 对应分享ID
	Reason      int    // 举报原因
	Description string // 补充描述

	// 关联模型
	Share Share `gorm:"save_associations:false:false"`
}

Report 举报模型

func (*Report) Create

func (report *Report) Create() error

Create 创建举报

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 {
	gorm.Model
	Password        string     // 分享密码,空值为非加密分享
	IsDir           bool       // 原始资源是否为目录
	UserID          uint       // 创建用户ID
	SourceID        uint       // 原始资源ID
	Views           int        // 浏览数
	Downloads       int        // 下载数
	RemainDownloads int        // 剩余下载配额,负值标识无限制
	Expires         *time.Time // 过期时间,空值表示无过期时间
	Score           int        // 每人次下载扣除积分
	PreviewEnabled  bool       // 是否允许直接预览
	SourceName      string     `gorm:"index:source"` // 用于搜索的字段

	// 数据库忽略字段
	User   User   `gorm:"PRELOAD:false,association_autoupdate:false"`
	File   File   `gorm:"PRELOAD:false,association_autoupdate:false"`
	Folder Folder `gorm:"PRELOAD:false,association_autoupdate:false"`
}

Share 分享模型

func GetShareByHashID

func GetShareByHashID(hashID string) *Share

GetShareByHashID 根据HashID查找分享

func ListShares

func ListShares(uid uint, page, pageSize int, order string, publicOnly bool) ([]Share, int)

ListShares 列出UID下的分享

func SearchShares

func SearchShares(page, pageSize int, order, keywords string) ([]Share, int)

SearchShares 根据关键字搜索分享

func (*Share) CanBeDownloadBy

func (share *Share) CanBeDownloadBy(user *User) error

CanBeDownloadBy 返回此分享是否可以被给定用户下载

func (*Share) Create

func (share *Share) Create() (uint, error)

Create 创建分享

func (*Share) Creator

func (share *Share) Creator() *User

Creator 获取分享的创建者

func (*Share) Delete

func (share *Share) Delete() error

Delete 删除分享

func (*Share) DownloadBy

func (share *Share) DownloadBy(user *User, c *gin.Context) error

DownloadBy 增加下载次数、检查积分等,匿名用户不会缓存

func (*Share) Downloaded

func (share *Share) Downloaded()

Downloaded 增加下载次数

func (*Share) IsAvailable

func (share *Share) IsAvailable() bool

IsAvailable 返回此分享是否可用(是否过期)

func (*Share) Purchase

func (share *Share) Purchase(user *User) error

Purchase 使用积分购买分享

func (*Share) Source

func (share *Share) Source() interface{}

Source 返回源对象

func (*Share) SourceFile

func (share *Share) SourceFile() *File

SourceFile 获取源文件

func (*Share) SourceFolder

func (share *Share) SourceFolder() *Folder

SourceFolder 获取源目录

func (*Share) Update

func (share *Share) Update(props map[string]interface{}) error

Update 更新分享属性

func (*Share) Viewed

func (share *Share) Viewed()

Viewed 增加访问次数

func (*Share) WasDownloadedBy

func (share *Share) WasDownloadedBy(user *User, c *gin.Context) (exist bool)

WasDownloadedBy 返回分享是否已被用户下载过

type StoragePack

type StoragePack struct {
	// 表字段
	gorm.Model
	Name        string
	UserID      uint
	ActiveTime  *time.Time
	ExpiredTime *time.Time `gorm:"index:expired"`
	Size        uint64
}

StoragePack 容量包模型

func GetExpiredStoragePack

func GetExpiredStoragePack() []StoragePack

GetExpiredStoragePack 获取已过期的容量包

func (*StoragePack) Create

func (pack *StoragePack) Create() (uint, error)

Create 创建容量包

func (*StoragePack) Delete

func (pack *StoragePack) Delete() error

Delete 删除容量包

type Tag

type Tag struct {
	gorm.Model
	Name       string // 标签名
	Icon       string // 图标标识
	Color      string // 图标颜色
	Type       int    // 标签类型(文件分类/目录直达)
	Expression string `gorm:"type:text"` // 搜索表表达式/直达路径
	UserID     uint   // 创建者ID
}

Tag 用户自定义标签

func GetTagsByID

func GetTagsByID(id, uid uint) (*Tag, error)

GetTagsByID 根据ID查找标签

func GetTagsByUID

func GetTagsByUID(uid uint) ([]Tag, error)

GetTagsByUID 根据用户ID查找标签

func (*Tag) Create

func (tag *Tag) Create() (uint, error)

Create 创建标签记录

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 任务模型

func GetTasksByID

func GetTasksByID(id interface{}) (*Task, error)

GetTasksByID 根据ID检索任务

func GetTasksByStatus

func GetTasksByStatus(status ...int) []Task

GetTasksByStatus 根据状态检索任务

func ListTasks

func ListTasks(uid uint, page, pageSize int, order string) ([]Task, int)

ListTasks 列出用户所属的任务

func (*Task) Create

func (task *Task) Create() (uint, error)

Create 创建任务记录

func (*Task) SetError

func (task *Task) SetError(err string) error

SetError 设定错误信息

func (*Task) SetProgress

func (task *Task) SetProgress(progress int) error

SetProgress 设定任务进度

func (*Task) SetStatus

func (task *Task) SetStatus(status int) error

SetStatus 设定任务状态

type TeamsFolderMember

type TeamsFolderMember struct {
	ID              uint `gorm:"primary_key"`
	CreatedAt       time.Time
	UpdatedAt       time.Time
	Password        string     // 分享密码,空值为非加密分享
	IsDir           bool       // 原始资源是否为目录
	UserID          uint       // 创建用户ID
	SourceID        uint       // 原始资源ID
	Views           int        // 浏览数
	Downloads       int        // 下载数
	RemainDownloads int        // 剩余下载配额,负值标识无限制
	Expires         *time.Time // 过期时间,空值表示无过期时间
	Score           int        // 每人次下载扣除积分
	GroupRole       int        // 角色
	PreviewEnabled  bool       // 是否允许直接预览
	SourceName      string     `gorm:"index:source"` // 用于搜索的字段
	DownloadEnabled bool       // 是否允许直接下载
	UploadEnabled   bool       // 是否允许直接上传
	EditEnabled     bool       // 是否允许直接编辑
	ManaEnabled     bool       // 是否允许直接管理
	IsRoot          bool       // 是否根节点
	// 数据库忽略字段
	User   User   `gorm:"PRELOAD:false,association_autoupdate:false"`
	File   File   `gorm:"PRELOAD:false,association_autoupdate:false"`
	Folder Folder `gorm:"PRELOAD:false,association_autoupdate:false"`
}

Share 分享模型

func GetFolderMemberPermissionByGroupRole

func GetFolderMemberPermissionByGroupRole(UserItem TeamsFolderMember) TeamsFolderMember

func GetTeamsFolderByHashID

func GetTeamsFolderByHashID(hashID string) *TeamsFolderMember

GetShareByHashID 根据HashID查找分享

func GetTeamsFolderMembers

func GetTeamsFolderMembers(source_id uint) (members []TeamsFolderMember)

func GetUserFolderMember

func GetUserFolderMember(user_id uint, source_id uint) (member TeamsFolderMember)

func GetUserTeamsFolder

func GetUserTeamsFolder(userId uint, sourceId uint) (source TeamsFolderMember)

func ListTeamsFolders

func ListTeamsFolders(uid uint, page, pageSize int, order string, publicOnly bool) ([]TeamsFolderMember, int)

ListShares 列出UID下的分享

func ListTeamsGroupFolder

func ListTeamsGroupFolder(folder_id uint, key string) ([]TeamsFolderMember, error)

func ListTeamsShare

func ListTeamsShare(uid uint, publicOnly bool) ([]TeamsFolderMember, error)

ListShares 列出UID下的分享

func SearchTeamsFolders

func SearchTeamsFolders(page, pageSize int, order, keywords string) ([]TeamsFolderMember, int)

SearchShares 根据关键字搜索分享

func (*TeamsFolderMember) CanBeDownloadBy

func (share *TeamsFolderMember) CanBeDownloadBy(user *User) error

CanBeDownloadBy 返回此分享是否可以被给定用户下载

func (*TeamsFolderMember) Create

func (share *TeamsFolderMember) Create() (uint, error)

Create 创建分享

func (*TeamsFolderMember) Creator

func (share *TeamsFolderMember) Creator() *User

Creator 获取分享的创建者

func (*TeamsFolderMember) Delete

func (share *TeamsFolderMember) Delete() error

Delete 删除分享

func (*TeamsFolderMember) DownloadBy

func (share *TeamsFolderMember) DownloadBy(user *User, c *gin.Context) error

DownloadBy 增加下载次数、检查积分等,匿名用户不会缓存

func (*TeamsFolderMember) Downloaded

func (share *TeamsFolderMember) Downloaded()

Downloaded 增加下载次数

func (*TeamsFolderMember) IsAvailable

func (share *TeamsFolderMember) IsAvailable() bool

IsAvailable 返回此分享是否可用(是否过期)

func (*TeamsFolderMember) Purchase

func (share *TeamsFolderMember) Purchase(user *User) error

Purchase 使用积分购买分享

func (*TeamsFolderMember) Source

func (share *TeamsFolderMember) Source() interface{}

Source 返回源对象

func (*TeamsFolderMember) SourceFile

func (share *TeamsFolderMember) SourceFile() *File

SourceFile 获取源文件

func (*TeamsFolderMember) SourceFolder

func (share *TeamsFolderMember) SourceFolder() *Folder

SourceFolder 获取源目录

func (*TeamsFolderMember) Update

func (share *TeamsFolderMember) Update(props map[string]interface{}) error

Update 更新分享属性

func (*TeamsFolderMember) Viewed

func (share *TeamsFolderMember) Viewed()

Viewed 增加访问次数

func (*TeamsFolderMember) WasDownloadedBy

func (share *TeamsFolderMember) WasDownloadedBy(user *User, c *gin.Context) (exist bool)

WasDownloadedBy 返回分享是否已被用户下载过

type User

type User struct {
	// 表字段
	gorm.Model
	Email           string `gorm:"type:varchar(100);unique_index"`
	Nick            string `gorm:"size:50"`
	Status          int
	GroupID         uint
	Storage         uint64
	OpenID          string
	TwoFactor       string
	Avatar          string
	Username        string
	Options         string `json:"-" gorm:"size:4294967295"`
	Authn           string `gorm:"size:4294967295"`
	Score           int
	PreviousGroupID uint       // 初始用户组
	GroupExpires    *time.Time // 用户组过期日期
	NotifyDate      *time.Time // 通知超出配额时的日期
	Phone           string

	// 关联模型
	Group  Group  `gorm:"save_associations:false:false"`
	Policy Policy `gorm:"-"`
	// 数据库忽略字段
	OptionsSerialized UserOption `gorm:"-"`
}

User 用户模型

func GetActiveUserByEmail

func GetActiveUserByEmail(email string) (User, error)

GetActiveUserByEmail 用Email获取可登录用户

func GetActiveUserByID

func GetActiveUserByID(ID interface{}) (User, error)

GetActiveUserByID 用ID获取可登录用户

func GetActiveUserByOpenID

func GetActiveUserByOpenID(openid string) (User, error)

GetActiveUserByOpenID 用OpenID获取可登录用户

func GetGroupExpiredUsers

func GetGroupExpiredUsers() []User

GetGroupExpiredUsers 获取用户组过期的用户

func GetTolerantExpiredUser

func GetTolerantExpiredUser() []User

GetTolerantExpiredUser 获取超过宽容期的用户

func GetUserByEmail

func GetUserByEmail(email string) (User, error)

GetUserByEmail 用Email获取用户

func GetUserByID

func GetUserByID(ID interface{}) (User, error)

GetUserByID 用ID获取用户

func GetUserByPhone

func GetUserByPhone(phone interface{}) (User, error)

GetUserByPhone 用Phone获取用户

func NewAnonymousUser

func NewAnonymousUser() *User

NewAnonymousUser 返回一个匿名用户

func NewUser

func NewUser() User

NewUser 返回一个新的空 User

func (*User) AddScore

func (user *User) AddScore(score int)

AddScore 增加积分

func (*User) AfterCreate

func (user *User) AfterCreate(tx *gorm.DB) (err error)

AfterCreate 创建用户后的钩子

func (*User) AfterFind

func (user *User) AfterFind() (err error)

AfterFind 找到用户后的钩子

func (*User) BeforeSave

func (user *User) BeforeSave() (err error)

BeforeSave Save用户前的钩子

func (*User) ChangeStorage

func (user *User) ChangeStorage(tx *gorm.DB, operator string, size uint64) error

ChangeStorage 更新用户容量

func (*User) ClearNotified

func (user *User) ClearNotified()

ClearNotified 清除用户通知标记

func (*User) DeductionStorage

func (user *User) DeductionStorage(size uint64) bool

DeductionStorage 减少用户已用容量

func (*User) GetAvailablePackSize

func (user *User) GetAvailablePackSize() uint64

GetAvailablePackSize 返回给定用户当前可用的容量包总容量

func (*User) GetAvailableStoragePacks

func (user *User) GetAvailableStoragePacks() []StoragePack

GetAvailableStoragePacks 返回用户可用的容量包

func (*User) GetPolicyByPreference

func (user *User) GetPolicyByPreference(preference uint) *Policy

GetPolicyByPreference 在可用存储策略中优先获取 preference

func (*User) GetPolicyID

func (user *User) GetPolicyID(folder *Folder) *Policy

GetPolicyID 获取给定目录的存储策略, 如果为 nil 则使用默认

func (*User) GetRemainingCapacity

func (user *User) GetRemainingCapacity() uint64

GetRemainingCapacity 获取剩余配额

func (*User) GroupFallback

func (user *User) GroupFallback()

GroupFallback 回退到初始用户组

func (*User) IncreaseStorage

func (user *User) IncreaseStorage(size uint64) bool

IncreaseStorage 检查并增加用户已用容量

func (*User) IncreaseStorageWithoutCheck

func (user *User) IncreaseStorageWithoutCheck(size uint64)

IncreaseStorageWithoutCheck 忽略可用容量,增加用户已用容量

func (*User) IsAnonymous

func (user *User) IsAnonymous() bool

IsAnonymous 返回是否为未登录用户

func (*User) Notified

func (user *User) Notified()

Notified 更新用户容量超额通知日期

func (*User) PayScore

func (user *User) PayScore(score int) bool

PayScore 扣除积分,返回是否成功

func (*User) RegisterAuthn

func (user *User) RegisterAuthn(credential *webauthn.Credential) error

RegisterAuthn 添加新的验证器

func (*User) RemoveAuthn

func (user *User) RemoveAuthn(id string)

RemoveAuthn 删除验证器

func (*User) Root

func (user *User) Root() (*Folder, error)

Root 获取用户的根目录

func (*User) SerializeOptions

func (user *User) SerializeOptions() (err error)

SerializeOptions 将序列后的Option写入到数据库字段

func (*User) SetStatus

func (user *User) SetStatus(status int)

SetStatus 设定用户状态

func (*User) TeamsCheckPassword

func (user *User) TeamsCheckPassword(username, password string) (bool, error)

func (*User) Update

func (user *User) Update(val map[string]interface{}) error

Update 更新用户

func (*User) UpdateOptions

func (user *User) UpdateOptions() error

UpdateOptions 更新用户偏好设定

func (*User) UpgradeGroup

func (user *User) UpgradeGroup(id uint, expires *time.Time) error

UpgradeGroup 升级用户组

func (User) WebAuthnCredentials

func (user User) WebAuthnCredentials() []webauthn.Credential

WebAuthnCredentials 获得已注册的验证器凭证

func (User) WebAuthnDisplayName

func (user User) WebAuthnDisplayName() string

WebAuthnDisplayName 获得用于展示的用户名

func (User) WebAuthnID

func (user User) WebAuthnID() []byte

WebAuthnID 返回用户ID

func (User) WebAuthnIcon

func (user User) WebAuthnIcon() string

WebAuthnIcon 获得用户头像

func (User) WebAuthnName

func (user User) WebAuthnName() string

WebAuthnName 返回用户名

type UserOption

type UserOption struct {
	ProfileOff      bool   `json:"profile_off,omitempty"`
	PreferredPolicy uint   `json:"preferred_policy,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"`                     // 根目录
}

Webdav 应用账户

func GetWebdavByPassword

func GetWebdavByPassword(password string, uid uint) (*Webdav, error)

GetWebdavByPassword 根据密码和用户查找Webdav应用

func ListWebDAVAccounts

func ListWebDAVAccounts(uid uint) []Webdav

ListWebDAVAccounts 列出用户的所有账号

func (*Webdav) Create

func (webdav *Webdav) Create() (uint, error)

Create 创建账户

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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