Skip to content

Commit

Permalink
feat: put directly api
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Jul 1, 2022
1 parent e389124 commit 8125fee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions server/controllers/fsmanage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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() {
Expand All @@ -206,18 +206,22 @@ 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,
Modified: time.Now(),
},
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
}
Expand Down
2 changes: 1 addition & 1 deletion server/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

0 comments on commit 8125fee

Please sign in to comment.