Feat: remote delete file / Fix: broken Filesystem recycle in upload request

This commit is contained in:
HFO4
2020-01-01 20:15:05 +08:00
parent e9f02940ee
commit ee08821361
14 changed files with 152 additions and 24 deletions

View File

@@ -265,7 +265,6 @@ func FileUploadStream(c *gin.Context) {
c.JSON(200, serializer.Err(serializer.CodePolicyNotAllowed, err.Error(), err))
return
}
defer fs.Recycle()
// 给文件系统分配钩子
fs.Use("BeforeUpload", filesystem.HookValidateFile)

View File

@@ -25,7 +25,6 @@ func SlaveUpload(c *gin.Context) {
c.JSON(200, serializer.Err(serializer.CodePolicyNotAllowed, err.Error(), err))
return
}
defer fs.Recycle()
fs.Handler = local.Handler{}
// 从请求中取得上传策略
@@ -115,3 +114,18 @@ func SlavePreview(c *gin.Context) {
c.JSON(200, ErrorResponse(err))
}
}
// SlaveDelete 从机删除
func SlaveDelete(c *gin.Context) {
// 创建上下文
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var service explorer.SlaveFilesService
if err := c.ShouldBindJSON(&service); err == nil {
res := service.Delete(ctx, c)
c.JSON(200, res)
} else {
c.JSON(200, ErrorResponse(err))
}
}

View File

@@ -39,6 +39,8 @@ func InitSlaveRouter() *gin.Engine {
v3.GET("download/:speed/:path/:name", controllers.SlaveDownload)
// 预览 / 外链
v3.GET("source/:speed/:path/:name", controllers.SlavePreview)
// 删除文件
v3.POST("delete", controllers.SlaveDelete)
}
return r
}