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/internal/sign"
|
||||||
"github.com/alist-org/alist/v3/server/common"
|
"github.com/alist-org/alist/v3/server/common"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
stdpath "path"
|
stdpath "path"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
@ -185,6 +184,7 @@ func FsRemove(c *gin.Context) {
|
|||||||
|
|
||||||
func FsPut(c *gin.Context) {
|
func FsPut(c *gin.Context) {
|
||||||
path := c.GetHeader("File-Path")
|
path := c.GetHeader("File-Path")
|
||||||
|
asTask := c.GetHeader("As-Task") == "true"
|
||||||
user := c.MustGet("user").(*model.User)
|
user := c.MustGet("user").(*model.User)
|
||||||
path = stdpath.Join(user.BasePath, path)
|
path = stdpath.Join(user.BasePath, path)
|
||||||
if !user.CanWrite() {
|
if !user.CanWrite() {
|
||||||
@ -206,9 +206,7 @@ func FsPut(c *gin.Context) {
|
|||||||
common.ErrorResp(c, err, 400)
|
common.ErrorResp(c, err, 400)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Debugf("c.Request.Close, %v", c.Request.Close)
|
stream := &model.FileStream{
|
||||||
c.Request.Close = false
|
|
||||||
if err := fs.PutAsTask(dir, &model.FileStream{
|
|
||||||
Obj: model.Object{
|
Obj: model.Object{
|
||||||
Name: name,
|
Name: name,
|
||||||
Size: size,
|
Size: size,
|
||||||
@ -216,8 +214,14 @@ func FsPut(c *gin.Context) {
|
|||||||
},
|
},
|
||||||
ReadCloser: c.Request.Body,
|
ReadCloser: c.Request.Body,
|
||||||
Mimetype: c.GetHeader("Content-Type"),
|
Mimetype: c.GetHeader("Content-Type"),
|
||||||
WebPutAsTask: true,
|
WebPutAsTask: asTask,
|
||||||
}); err != nil {
|
}
|
||||||
|
if asTask {
|
||||||
|
err = fs.PutAsTask(dir, stream)
|
||||||
|
} else {
|
||||||
|
err = fs.PutDirectly(c, dir, stream)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
common.ErrorResp(c, err, 500)
|
common.ErrorResp(c, err, 500)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -94,6 +94,6 @@ func Init(r *gin.Engine) {
|
|||||||
func Cors(r *gin.Engine) {
|
func Cors(r *gin.Engine) {
|
||||||
config := cors.DefaultConfig()
|
config := cors.DefaultConfig()
|
||||||
config.AllowAllOrigins = true
|
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))
|
r.Use(cors.New(config))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user