feat: put directly api

This commit is contained in:
Noah Hsu 2022-07-01 17:11:22 +08:00
parent e3891246b9
commit 8125fee3f9
2 changed files with 11 additions and 7 deletions

View File

@ -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
}

View File

@ -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))
}