Documentation ¶
Index ¶
- Constants
- Variables
- func GenericAfterUpdate(ctx context.Context, fs *FileSystem, newFile fsctx.FileHeader) error
- func GenericAfterUpload(ctx context.Context, fs *FileSystem, fileHeader fsctx.FileHeader) error
- func HookCancelContext(ctx context.Context, fs *FileSystem, file fsctx.FileHeader) error
- func HookChunkUploadFailed(ctx context.Context, fs *FileSystem, fileHeader fsctx.FileHeader) error
- func HookChunkUploaded(ctx context.Context, fs *FileSystem, fileHeader fsctx.FileHeader) error
- func HookCleanFileContent(ctx context.Context, fs *FileSystem, file fsctx.FileHeader) error
- func HookClearFileHeaderSize(ctx context.Context, fs *FileSystem, fileHeader fsctx.FileHeader) error
- func HookClearFileSize(ctx context.Context, fs *FileSystem, file fsctx.FileHeader) error
- func HookDeleteTempFile(ctx context.Context, fs *FileSystem, file fsctx.FileHeader) error
- func HookResetPolicy(ctx context.Context, fs *FileSystem, file fsctx.FileHeader) error
- func HookUpdateSourceName(ctx context.Context, fs *FileSystem, file fsctx.FileHeader) error
- func HookValidateCapacity(ctx context.Context, fs *FileSystem, file fsctx.FileHeader) error
- func HookValidateCapacityDiff(ctx context.Context, fs *FileSystem, newFile fsctx.FileHeader) error
- func HookValidateFile(ctx context.Context, fs *FileSystem, file fsctx.FileHeader) error
- func NewWebdavAfterUploadHook(request *http.Request) func(ctx context.Context, fs *FileSystem, newFile fsctx.FileHeader) error
- type FileSystem
- func (fs *FileSystem) AddFile(ctx context.Context, parent *model.Folder, file fsctx.FileHeader) (*model.File, error)
- func (fs *FileSystem) CancelUpload(ctx context.Context, path string, file fsctx.FileHeader)
- func (fs *FileSystem) CleanHooks(name string)
- func (fs *FileSystem) CleanTargets()
- func (fs *FileSystem) Compress(ctx context.Context, writer io.Writer, folderIDs, fileIDs []uint, ...) error
- func (fs *FileSystem) Copy(ctx context.Context, dirs, files []uint, src, dst string) error
- func (fs *FileSystem) CreateDirectory(ctx context.Context, fullPath string) (*model.Folder, error)
- func (fs *FileSystem) CreateUploadSession(ctx context.Context, file *fsctx.FileStream) (*serializer.UploadCredential, error)
- func (fs *FileSystem) Decompress(ctx context.Context, src, dst, encoding string) error
- func (fs *FileSystem) Delete(ctx context.Context, dirs, files []uint, force, unlink bool) error
- func (fs *FileSystem) DispatchHandler() error
- func (fs *FileSystem) GenerateSavePath(ctx context.Context, file fsctx.FileHeader) string
- func (fs *FileSystem) GenerateThumbnailSize(w, h int) (uint, uint)
- func (fs *FileSystem) GetContent(ctx context.Context, id uint) (response.RSCloser, error)
- func (fs *FileSystem) GetDownloadContent(ctx context.Context, id uint) (response.RSCloser, error)
- func (fs *FileSystem) GetDownloadURL(ctx context.Context, id uint, timeout string) (string, error)
- func (fs *FileSystem) GetPhysicalFileContent(ctx context.Context, path string) (response.RSCloser, error)
- func (fs *FileSystem) GetSource(ctx context.Context, fileID uint) (string, error)
- func (fs *FileSystem) GetThumb(ctx context.Context, id uint) (*response.ContentResponse, error)
- func (fs *FileSystem) GroupFileByPolicy(ctx context.Context, files []model.File) map[uint][]*model.File
- func (fs *FileSystem) IsChildFileExist(folder *model.Folder, name string) (bool, *model.File)
- func (fs *FileSystem) IsFileExist(fullPath string) (bool, *model.File)
- func (fs *FileSystem) IsPathExist(path string) (bool, *model.Folder)
- func (fs *FileSystem) List(ctx context.Context, dirPath string, pathProcessor func(string) string) ([]serializer.Object, error)
- func (fs *FileSystem) ListDeleteDirs(ctx context.Context, ids []uint) error
- func (fs *FileSystem) ListDeleteFiles(ctx context.Context, ids []uint) error
- func (fs *FileSystem) ListPhysical(ctx context.Context, dirPath string) ([]serializer.Object, error)
- func (fs *FileSystem) Move(ctx context.Context, dirs, files []uint, src, dst string) error
- func (fs *FileSystem) Preview(ctx context.Context, id uint, isText bool) (*response.ContentResponse, error)
- func (fs *FileSystem) Recycle()
- func (fs *FileSystem) Rename(ctx context.Context, dir, file []uint, new string) (err error)
- func (fs *FileSystem) ResetFileIfNotExist(ctx context.Context, path string) error
- func (fs *FileSystem) SaveTo(ctx context.Context, path string) error
- func (fs *FileSystem) Search(ctx context.Context, keywords ...interface{}) ([]serializer.Object, error)
- func (fs *FileSystem) SetTargetByInterface(target interface{}) error
- func (fs *FileSystem) SetTargetDir(dirs *[]model.Folder)
- func (fs *FileSystem) SetTargetFile(files *[]model.File)
- func (fs *FileSystem) SetTargetFileByIDs(ids []uint) error
- func (fs *FileSystem) SignURL(ctx context.Context, file *model.File, ttl int64, isDownload bool) (string, error)
- func (fs *FileSystem) SwitchToShadowHandler(master cluster.Node, masterURL, masterID string)
- func (fs *FileSystem) SwitchToSlaveHandler(node cluster.Node)
- func (fs *FileSystem) Trigger(ctx context.Context, name string, file fsctx.FileHeader) error
- func (fs *FileSystem) Upload(ctx context.Context, file *fsctx.FileStream) (err error)
- func (fs *FileSystem) UploadFromPath(ctx context.Context, src, dst string, mode fsctx.WriteMode) error
- func (fs *FileSystem) UploadFromStream(ctx context.Context, file *fsctx.FileStream, resetPolicy bool) error
- func (fs *FileSystem) Use(name string, hook Hook)
- func (fs *FileSystem) ValidateCapacity(ctx context.Context, size uint64) bool
- func (fs *FileSystem) ValidateExtension(ctx context.Context, fileName string) bool
- func (fs *FileSystem) ValidateFileSize(ctx context.Context, size uint64) bool
- func (fs *FileSystem) ValidateLegalName(ctx context.Context, name string) bool
- type Hook
- type Pool
Constants ¶
const ( UploadSessionMetaKey = "upload_session" UploadSessionCtx = "uploadSession" UserCtx = "user" UploadSessionCachePrefix = "callback_" )
Variables ¶
var ( ErrUnknownPolicyType = serializer.NewError(serializer.CodeInternalSetting, "Unknown policy type", nil) ErrFileSizeTooBig = serializer.NewError(serializer.CodeFileTooLarge, "File is too large", nil) ErrFileExtensionNotAllowed = serializer.NewError(serializer.CodeFileTypeNotAllowed, "File type not allowed", nil) ErrInsufficientCapacity = serializer.NewError(serializer.CodeInsufficientCapacity, "Insufficient capacity", nil) ErrIllegalObjectName = serializer.NewError(serializer.CodeIllegalObjectName, "Invalid object name", nil) ErrClientCanceled = errors.New("Client canceled operation") ErrRootProtected = serializer.NewError(serializer.CodeRootProtected, "Root protected", nil) ErrInsertFileRecord = serializer.NewError(serializer.CodeDBError, "Failed to create file record", nil) ErrFileExisted = serializer.NewError(serializer.CodeObjectExist, "Object existed", nil) ErrFileUploadSessionExisted = serializer.NewError(serializer.CodeConflictUploadOngoing, "Upload session existed", nil) ErrPathNotExist = serializer.NewError(serializer.CodeParentNotExist, "Path not exist", nil) ErrObjectNotExist = serializer.NewError(serializer.CodeParentNotExist, "Object not exist", nil) ErrIO = serializer.NewError(serializer.CodeIOFailed, "Failed to read file data", nil) ErrDBListObjects = serializer.NewError(serializer.CodeDBError, "Failed to list object records", nil) ErrDBDeleteObjects = serializer.NewError(serializer.CodeDBError, "Failed to delete object records", nil) ErrOneObjectOnly = serializer.ParamErr("You can only copy one object at the same time", nil) )
var FSPool = sync.Pool{ New: func() interface{} { return &FileSystem{} }, }
FSPool 文件系统资源池
Functions ¶
func GenericAfterUpdate ¶
func GenericAfterUpdate(ctx context.Context, fs *FileSystem, newFile fsctx.FileHeader) error
GenericAfterUpdate 文件内容更新后
func GenericAfterUpload ¶
func GenericAfterUpload(ctx context.Context, fs *FileSystem, fileHeader fsctx.FileHeader) error
GenericAfterUpload 文件上传完成后,包含数据库操作
func HookCancelContext ¶
func HookCancelContext(ctx context.Context, fs *FileSystem, file fsctx.FileHeader) error
HookCancelContext 取消上下文
func HookChunkUploadFailed ¶
func HookChunkUploadFailed(ctx context.Context, fs *FileSystem, fileHeader fsctx.FileHeader) error
HookChunkUploadFailed 单个分片上传失败后
func HookChunkUploaded ¶
func HookChunkUploaded(ctx context.Context, fs *FileSystem, fileHeader fsctx.FileHeader) error
HookChunkUploadFinished 单个分片上传结束后
func HookCleanFileContent ¶
func HookCleanFileContent(ctx context.Context, fs *FileSystem, file fsctx.FileHeader) error
HookCleanFileContent 清空文件内容
func HookClearFileHeaderSize ¶
func HookClearFileHeaderSize(ctx context.Context, fs *FileSystem, fileHeader fsctx.FileHeader) error
HookClearFileHeaderSize 将FileHeader大小设定为0
func HookClearFileSize ¶
func HookClearFileSize(ctx context.Context, fs *FileSystem, file fsctx.FileHeader) error
HookClearFileSize 将原始文件的尺寸设为0
func HookDeleteTempFile ¶
func HookDeleteTempFile(ctx context.Context, fs *FileSystem, file fsctx.FileHeader) error
HookDeleteTempFile 删除已保存的临时文件
func HookResetPolicy ¶
func HookResetPolicy(ctx context.Context, fs *FileSystem, file fsctx.FileHeader) error
HookResetPolicy 重设存储策略为上下文已有文件
func HookUpdateSourceName ¶
func HookUpdateSourceName(ctx context.Context, fs *FileSystem, file fsctx.FileHeader) error
HookUpdateSourceName 更新文件SourceName
func HookValidateCapacity ¶
func HookValidateCapacity(ctx context.Context, fs *FileSystem, file fsctx.FileHeader) error
HookValidateCapacity 验证用户容量
func HookValidateCapacityDiff ¶
func HookValidateCapacityDiff(ctx context.Context, fs *FileSystem, newFile fsctx.FileHeader) error
HookValidateCapacityDiff 根据原有文件和新文件的大小验证用户容量
func HookValidateFile ¶
func HookValidateFile(ctx context.Context, fs *FileSystem, file fsctx.FileHeader) error
HookValidateFile 一系列对文件检验的集合
func NewWebdavAfterUploadHook ¶
func NewWebdavAfterUploadHook(request *http.Request) func(ctx context.Context, fs *FileSystem, newFile fsctx.FileHeader) error
NewWebdavAfterUploadHook 每次创建一个新的钩子函数 rclone 在 PUT 请求里有 OC-Checksum 字符串 和 X-OC-Mtime
Types ¶
type FileSystem ¶
type FileSystem struct { // 文件系统所有者 User *model.User // 操作文件使用的存储策略 Policy *model.Policy // 当前正在处理的文件对象 FileTarget []model.File // 当前正在处理的目录对象 DirTarget []model.Folder // 相对根目录 Root *model.Folder // 互斥锁 Lock sync.Mutex /* 钩子函数 */ Hooks map[string][]Hook /* 文件系统处理适配器 */ Handler driver.Handler // contains filtered or unexported fields }
FileSystem 管理文件的文件系统
func NewAnonymousFileSystem ¶
func NewAnonymousFileSystem() (*FileSystem, error)
NewAnonymousFileSystem 初始化匿名文件系统
func NewFileSystem ¶
func NewFileSystem(user *model.User) (*FileSystem, error)
NewFileSystem 初始化一个文件系统
func NewFileSystemFromCallback ¶
func NewFileSystemFromCallback(c *gin.Context) (*FileSystem, error)
NewFileSystemFromCallback 从gin.Context创建回调用文件系统
func NewFileSystemFromContext ¶
func NewFileSystemFromContext(c *gin.Context) (*FileSystem, error)
NewFileSystemFromContext 从gin.Context创建文件系统
func (*FileSystem) AddFile ¶
func (fs *FileSystem) AddFile(ctx context.Context, parent *model.Folder, file fsctx.FileHeader) (*model.File, error)
AddFile 新增文件记录
func (*FileSystem) CancelUpload ¶
func (fs *FileSystem) CancelUpload(ctx context.Context, path string, file fsctx.FileHeader)
CancelUpload 监测客户端取消上传
func (*FileSystem) CleanHooks ¶
func (fs *FileSystem) CleanHooks(name string)
CleanHooks 清空钩子,name为空表示全部清空
func (*FileSystem) Compress ¶
func (fs *FileSystem) Compress(ctx context.Context, writer io.Writer, folderIDs, fileIDs []uint, isArchive bool) error
Compress 创建给定目录和文件的压缩文件
func (*FileSystem) CreateDirectory ¶
CreateDirectory 根据给定的完整创建目录,支持递归创建。如果目录已存在,则直接 返回已存在的目录。
func (*FileSystem) CreateUploadSession ¶
func (fs *FileSystem) CreateUploadSession(ctx context.Context, file *fsctx.FileStream) (*serializer.UploadCredential, error)
CreateUploadSession 创建上传会话
func (*FileSystem) Decompress ¶
func (fs *FileSystem) Decompress(ctx context.Context, src, dst, encoding string) error
Decompress 解压缩给定压缩文件到dst目录
func (*FileSystem) Delete ¶
Delete 递归删除对象, force 为 true 时强制删除文件记录,忽略物理删除是否成功; unlink 为 true 时只删除虚拟文件系统的文件记录,不删除物理文件。
func (*FileSystem) DispatchHandler ¶
func (fs *FileSystem) DispatchHandler() error
DispatchHandler 根据存储策略分配文件适配器
func (*FileSystem) GenerateSavePath ¶
func (fs *FileSystem) GenerateSavePath(ctx context.Context, file fsctx.FileHeader) string
GenerateSavePath 生成要存放文件的路径 TODO 完善测试
func (*FileSystem) GenerateThumbnailSize ¶
func (fs *FileSystem) GenerateThumbnailSize(w, h int) (uint, uint)
GenerateThumbnailSize 获取要生成的缩略图的尺寸
func (*FileSystem) GetContent ¶
GetContent 获取文件内容,path为虚拟路径
func (*FileSystem) GetDownloadContent ¶
GetDownloadContent 获取用于下载的文件流
func (*FileSystem) GetDownloadURL ¶
GetDownloadURL 创建文件下载链接, timeout 为数据库中存储过期时间的字段
func (*FileSystem) GetPhysicalFileContent ¶
func (fs *FileSystem) GetPhysicalFileContent(ctx context.Context, path string) (response.RSCloser, error)
GetPhysicalFileContent 根据文件物理路径获取文件流
func (*FileSystem) GetThumb ¶
func (fs *FileSystem) GetThumb(ctx context.Context, id uint) (*response.ContentResponse, error)
GetThumb 获取文件的缩略图
func (*FileSystem) GroupFileByPolicy ¶
func (fs *FileSystem) GroupFileByPolicy(ctx context.Context, files []model.File) map[uint][]*model.File
GroupFileByPolicy 将目标文件按照存储策略分组
func (*FileSystem) IsChildFileExist ¶
IsChildFileExist 确定folder目录下是否有名为name的文件
func (*FileSystem) IsFileExist ¶
func (fs *FileSystem) IsFileExist(fullPath string) (bool, *model.File)
IsFileExist 返回给定路径的文件是否存在
func (*FileSystem) IsPathExist ¶
func (fs *FileSystem) IsPathExist(path string) (bool, *model.Folder)
IsPathExist 返回给定目录是否存在 如果存在就返回目录
func (*FileSystem) List ¶
func (fs *FileSystem) List(ctx context.Context, dirPath string, pathProcessor func(string) string) ([]serializer.Object, error)
List 列出路径下的内容, pathProcessor为最终对象路径的处理钩子。 有些情况下(如在分享页面列对象)时, 路径需要截取掉被分享目录路径之前的部分。
func (*FileSystem) ListDeleteDirs ¶
func (fs *FileSystem) ListDeleteDirs(ctx context.Context, ids []uint) error
ListDeleteDirs 递归列出要删除目录,及目录下所有文件
func (*FileSystem) ListDeleteFiles ¶
func (fs *FileSystem) ListDeleteFiles(ctx context.Context, ids []uint) error
ListDeleteFiles 根据给定的路径列出要删除的文件
func (*FileSystem) ListPhysical ¶
func (fs *FileSystem) ListPhysical(ctx context.Context, dirPath string) ([]serializer.Object, error)
ListPhysical 列出存储策略中的外部目录 TODO:测试
func (*FileSystem) Preview ¶
func (fs *FileSystem) Preview(ctx context.Context, id uint, isText bool) (*response.ContentResponse, error)
Preview 预览文件
path - 文件虚拟路径 isText - 是否为文本文件,文本文件会忽略重定向,直接由 服务端拉取中转给用户,故会对文件大小进行限制
func (*FileSystem) ResetFileIfNotExist ¶
func (fs *FileSystem) ResetFileIfNotExist(ctx context.Context, path string) error
ResetFileIfNotExist 重设当前目标文件为 path,如果当前目标为空
func (*FileSystem) SaveTo ¶
func (fs *FileSystem) SaveTo(ctx context.Context, path string) error
SaveTo 将别人分享的文件转存到目标路径下
func (*FileSystem) Search ¶
func (fs *FileSystem) Search(ctx context.Context, keywords ...interface{}) ([]serializer.Object, error)
Search 搜索文件
func (*FileSystem) SetTargetByInterface ¶
func (fs *FileSystem) SetTargetByInterface(target interface{}) error
SetTargetByInterface 根据 model.File 或者 model.Folder 设置目标对象 TODO 测试
func (*FileSystem) SetTargetDir ¶
func (fs *FileSystem) SetTargetDir(dirs *[]model.Folder)
SetTargetDir 设置当前处理的目标目录
func (*FileSystem) SetTargetFile ¶
func (fs *FileSystem) SetTargetFile(files *[]model.File)
SetTargetFile 设置当前处理的目标文件
func (*FileSystem) SetTargetFileByIDs ¶
func (fs *FileSystem) SetTargetFileByIDs(ids []uint) error
SetTargetFileByIDs 根据文件ID设置目标文件,忽略用户ID
func (*FileSystem) SignURL ¶
func (fs *FileSystem) SignURL(ctx context.Context, file *model.File, ttl int64, isDownload bool) (string, error)
SignURL 签名文件原始 URL
func (*FileSystem) SwitchToShadowHandler ¶
func (fs *FileSystem) SwitchToShadowHandler(master cluster.Node, masterURL, masterID string)
SwitchToShadowHandler 将负责上传的 Handler 切换为从机节点转存使用的影子处理器
func (*FileSystem) SwitchToSlaveHandler ¶
func (fs *FileSystem) SwitchToSlaveHandler(node cluster.Node)
SwitchToSlaveHandler 将负责上传的 Handler 切换为从机节点
func (*FileSystem) Trigger ¶
func (fs *FileSystem) Trigger(ctx context.Context, name string, file fsctx.FileHeader) error
Trigger 触发钩子,遇到第一个错误时 返回错误,后续钩子不会继续执行
func (*FileSystem) Upload ¶
func (fs *FileSystem) Upload(ctx context.Context, file *fsctx.FileStream) (err error)
Upload 上传文件
func (*FileSystem) UploadFromPath ¶
func (fs *FileSystem) UploadFromPath(ctx context.Context, src, dst string, mode fsctx.WriteMode) error
UploadFromPath 将本机已有文件上传到用户的文件系统
func (*FileSystem) UploadFromStream ¶
func (fs *FileSystem) UploadFromStream(ctx context.Context, file *fsctx.FileStream, resetPolicy bool) error
UploadFromStream 从文件流上传文件
func (*FileSystem) ValidateCapacity ¶
func (fs *FileSystem) ValidateCapacity(ctx context.Context, size uint64) bool
ValidateCapacity 验证并扣除用户容量
func (*FileSystem) ValidateExtension ¶
func (fs *FileSystem) ValidateExtension(ctx context.Context, fileName string) bool
ValidateExtension 验证文件扩展名
func (*FileSystem) ValidateFileSize ¶
func (fs *FileSystem) ValidateFileSize(ctx context.Context, size uint64) bool
ValidateFileSize 验证上传的文件大小是否超出限制
func (*FileSystem) ValidateLegalName ¶
func (fs *FileSystem) ValidateLegalName(ctx context.Context, name string) bool
ValidateLegalName 验证文件名/文件夹名是否合法
type Hook ¶
type Hook func(ctx context.Context, fs *FileSystem, file fsctx.FileHeader) error
Hook 钩子函数
func HookDeleteUploadSession ¶
HookChunkUploadFinished 分片上传结束后处理文件
func HookPopPlaceholderToFile ¶
HookPopPlaceholderToFile 将占位文件提升为正式文件
func HookTruncateFileTo ¶
HookTruncateFileTo 将物理文件截断至 size
func SlaveAfterUpload ¶
func SlaveAfterUpload(session *serializer.UploadSession) Hook
SlaveAfterUpload Slave模式下上传完成钩子