Feat: upload session recycle crontab job / API for cleanup all upload session

This commit is contained in:
HFO4
2022-02-27 14:16:36 +08:00
parent 3444b4a75e
commit 7dd636da74
21 changed files with 248 additions and 21 deletions

View File

@@ -343,13 +343,38 @@ func FileUpload(c *gin.Context) {
//})
}
// DeleteUploadCredential 删除上传会话
func DeleteUploadCredential(c *gin.Context) {
// 创建上下文
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var service explorer.UploadSessionService
if err := c.ShouldBindUri(&service); err == nil {
res := service.Delete(ctx, c)
c.JSON(200, res)
} else {
c.JSON(200, ErrorResponse(err))
}
}
// DeleteAllCredential 删除全部上传会话
func DeleteAllCredential(c *gin.Context) {
// 创建上下文
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
res := explorer.DeleteAllUploadSession(ctx, c)
c.JSON(200, res)
}
// GetUploadCredential 创建上传会话
func GetUploadCredential(c *gin.Context) {
// 创建上下文
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var service explorer.UploadSessionService
var service explorer.CreateUploadSessionService
if err := c.ShouldBindJSON(&service); err == nil {
res := service.Create(ctx, c)
c.JSON(200, res)

View File

@@ -504,10 +504,18 @@ func InitMasterRouter() *gin.Engine {
// 文件
file := auth.Group("file", middleware.HashID(hashid.FileID))
{
// 文件上传
file.POST("upload/:sessionId/:index", controllers.FileUpload)
// 创建上传会话
file.PUT("upload", controllers.GetUploadCredential)
// 上传
upload := file.Group("upload")
{
// 文件上传
upload.POST(":sessionId/:index", controllers.FileUpload)
// 创建上传会话
upload.PUT("", controllers.GetUploadCredential)
// 删除给定上传会话
upload.DELETE(":sessionId", controllers.DeleteUploadCredential)
// 删除全部上传会话
upload.DELETE("", controllers.DeleteAllCredential)
}
// 更新文件
file.PUT("update/:id", controllers.PutContent)
// 创建空白文件