Feat: adapt major methods of WebDAV for Cloudreve file system

This commit is contained in:
HFO4
2019-12-17 12:02:50 +08:00
parent 1dac66e632
commit 9fdf2fe7ab
10 changed files with 327 additions and 258 deletions

View File

@@ -13,4 +13,6 @@ const (
PathCtx
// FileModelCtx 文件数据库模型
FileModelCtx
// HTTPCtx HTTP请求的上下文
HTTPCtx
)

View File

@@ -161,6 +161,9 @@ func GenericAfterUpdate(ctx context.Context, fs *FileSystem) error {
if !ok {
return ErrObjectNotExist
}
fs.SetTargetFile(&[]model.File{originFile})
newFile, ok := ctx.Value(fsctx.FileHeaderCtx).(FileHeader)
if !ok {
return ErrObjectNotExist
@@ -205,6 +208,7 @@ func GenericAfterUpload(ctx context.Context, fs *FileSystem) error {
if err != nil {
return ErrInsertFileRecord
}
fs.SetTargetFile(&[]model.File{*file})
// 异步尝试生成缩略图
go fs.GenerateThumbnail(ctx, file)

View File

@@ -78,9 +78,15 @@ func (fs *FileSystem) GenerateSavePath(ctx context.Context, file FileHeader) str
// CancelUpload 监测客户端取消上传
func (fs *FileSystem) CancelUpload(ctx context.Context, path string, file FileHeader) {
ginCtx := ctx.Value(fsctx.GinCtx).(*gin.Context)
var reqContext context.Context
if ginCtx, ok := ctx.Value(fsctx.GinCtx).(*gin.Context); ok {
reqContext = ginCtx.Request.Context()
} else {
reqContext = ctx.Value(fsctx.HTTPCtx).(context.Context)
}
select {
case <-ginCtx.Request.Context().Done():
case <-reqContext.Done():
select {
case <-ctx.Done():
// 客户端正常关闭,不执行操作