✨ rename and mkdir api
This commit is contained in:
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)
|
||||
}
|
Reference in New Issue
Block a user