mirror of
https://github.com/AlistGo/alist.git
synced 2025-04-22 21:04:07 +08:00
feat: put directly api
This commit is contained in:
parent
e3891246b9
commit
8125fee3f9
@ -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
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user