✨ rename and mkdir api
This commit is contained in:
parent
4a21b6fe1d
commit
dcb4ec695f
34
server/controllers/file/mkdir.go
Normal file
34
server/controllers/file/mkdir.go
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package file
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/Xhofe/alist/drivers/operate"
|
||||||
|
"github.com/Xhofe/alist/server/common"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MkdirReq struct {
|
||||||
|
Path string `json:"path"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func Mkdir(c *gin.Context) {
|
||||||
|
var req MkdirReq
|
||||||
|
if err := c.ShouldBind(&req); err != nil {
|
||||||
|
common.ErrorResp(c, err, 400)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
account, path_, driver, err := common.ParsePath(req.Path)
|
||||||
|
if err != nil {
|
||||||
|
common.ErrorResp(c, err, 500)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if path_ == "/" {
|
||||||
|
common.ErrorStrResp(c, "Folder name can't be empty", 400)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = operate.MakeDir(driver, account, path_, true)
|
||||||
|
if err != nil {
|
||||||
|
common.ErrorResp(c, err, 500)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
common.SuccessResp(c)
|
||||||
|
}
|
36
server/controllers/file/raname.go
Normal file
36
server/controllers/file/raname.go
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package file
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/Xhofe/alist/drivers/operate"
|
||||||
|
"github.com/Xhofe/alist/server/common"
|
||||||
|
"github.com/Xhofe/alist/utils"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
type RenameReq struct {
|
||||||
|
Path string `json:"path"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func Rename(c *gin.Context) {
|
||||||
|
var req RenameReq
|
||||||
|
if err := c.ShouldBind(&req); err != nil {
|
||||||
|
common.ErrorResp(c, err, 400)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
account, path_, driver, err := common.ParsePath(req.Path)
|
||||||
|
if err != nil {
|
||||||
|
common.ErrorResp(c, err, 500)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if path_ == "/" {
|
||||||
|
common.ErrorStrResp(c, "Can't account name here", 400)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = operate.Move(driver, account, path_, utils.Join(utils.Dir(path_), req.Name), true)
|
||||||
|
if err != nil {
|
||||||
|
common.ErrorResp(c, err, 500)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
common.SuccessResp(c)
|
||||||
|
}
|
@ -128,6 +128,7 @@ func Proxy(c *gin.Context) {
|
|||||||
defer func() {
|
defer func() {
|
||||||
_ = res.Body.Close()
|
_ = res.Body.Close()
|
||||||
}()
|
}()
|
||||||
|
log.Debugf("proxy status: %d", res.StatusCode)
|
||||||
w.WriteHeader(res.StatusCode)
|
w.WriteHeader(res.StatusCode)
|
||||||
for h, v := range res.Header {
|
for h, v := range res.Header {
|
||||||
w.Header()[h] = v
|
w.Header()[h] = v
|
||||||
|
@ -51,6 +51,8 @@ func InitApiRouter(r *gin.Engine) {
|
|||||||
|
|
||||||
admin.POST("/link", controllers.Link)
|
admin.POST("/link", controllers.Link)
|
||||||
admin.DELETE("/files", file.DeleteFiles)
|
admin.DELETE("/files", file.DeleteFiles)
|
||||||
|
admin.POST("/mkdir", file.Mkdir)
|
||||||
|
admin.POST("rename", file.Rename)
|
||||||
}
|
}
|
||||||
WebDav(r)
|
WebDav(r)
|
||||||
Static(r)
|
Static(r)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user