From 8125fee3f936af0d54ecd02bbcddbd6174d45314 Mon Sep 17 00:00:00 2001 From: Noah Hsu Date: Fri, 1 Jul 2022 17:11:22 +0800 Subject: [PATCH] feat: put directly api --- server/controllers/fsmanage.go | 16 ++++++++++------ server/router.go | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/server/controllers/fsmanage.go b/server/controllers/fsmanage.go index 12deefa1aea..297086cdd94 100644 --- a/server/controllers/fsmanage.go +++ b/server/controllers/fsmanage.go @@ -9,7 +9,6 @@ import ( "github.com/alist-org/alist/v3/internal/sign" "github.com/alist-org/alist/v3/server/common" "github.com/gin-gonic/gin" - log "github.com/sirupsen/logrus" stdpath "path" "strconv" "time" @@ -185,6 +184,7 @@ func FsRemove(c *gin.Context) { func FsPut(c *gin.Context) { path := c.GetHeader("File-Path") + asTask := c.GetHeader("As-Task") == "true" user := c.MustGet("user").(*model.User) path = stdpath.Join(user.BasePath, path) if !user.CanWrite() { @@ -206,9 +206,7 @@ func FsPut(c *gin.Context) { common.ErrorResp(c, err, 400) return } - log.Debugf("c.Request.Close, %v", c.Request.Close) - c.Request.Close = false - if err := fs.PutAsTask(dir, &model.FileStream{ + stream := &model.FileStream{ Obj: model.Object{ Name: name, Size: size, @@ -216,8 +214,14 @@ func FsPut(c *gin.Context) { }, ReadCloser: c.Request.Body, Mimetype: c.GetHeader("Content-Type"), - WebPutAsTask: true, - }); err != nil { + WebPutAsTask: asTask, + } + if asTask { + err = fs.PutAsTask(dir, stream) + } else { + err = fs.PutDirectly(c, dir, stream) + } + if err != nil { common.ErrorResp(c, err, 500) return } diff --git a/server/router.go b/server/router.go index 3d59fe5f15c..c4e4273ac26 100644 --- a/server/router.go +++ b/server/router.go @@ -94,6 +94,6 @@ func Init(r *gin.Engine) { func Cors(r *gin.Engine) { config := cors.DefaultConfig() config.AllowAllOrigins = true - config.AllowHeaders = append(config.AllowHeaders, "Authorization", "range", "File-Path") + config.AllowHeaders = append(config.AllowHeaders, "Authorization", "range", "File-Path", "As-Task") r.Use(cors.New(config)) }