🚧 add folder api

pull/548/head
微凉 2022-01-18 19:08:44 +08:00
parent 6d34e88360
commit 54272db59c
2 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,52 @@
package file
import (
"github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/server/common"
"github.com/gin-gonic/gin"
)
type FolderReq struct {
Path string `json:"path"`
}
func Folder(c *gin.Context) {
var req FolderReq
if err := c.ShouldBind(&req); err != nil {
common.ErrorResp(c, err, 400)
return
}
var files []model.File
var err error
if model.AccountsCount() > 1 && req.Path == "/" {
files, err = model.GetAccountFiles()
if err != nil {
common.ErrorResp(c, err, 500)
return
}
} else {
account, path, driver, err := common.ParsePath(req.Path)
if err != nil {
common.ErrorResp(c, err, 500)
return
}
file, rawFiles, err := driver.Path(path, account)
if err != nil {
common.ErrorResp(c, err, 500)
return
}
if file != nil {
common.ErrorStrResp(c, "Not folder", 400)
}
for _, file := range rawFiles {
if file.IsDir() {
files = append(files, file)
}
}
}
c.JSON(200, common.Resp{
Code: 200,
Message: "success",
Data: files,
})
}

View File

@ -54,6 +54,7 @@ func InitApiRouter(r *gin.Engine) {
admin.POST("/mkdir", file.Mkdir)
admin.POST("/rename", file.Rename)
admin.POST("/move", file.Move)
admin.POST("/folder", file.Folder)
}
WebDav(r)
Static(r)