✨ basic structure
This commit is contained in:
46
server/path.go
Normal file
46
server/path.go
Normal file
@ -0,0 +1,46 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"github.com/Xhofe/alist/model"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type PathReq struct {
|
||||
Path string `json:"Path"`
|
||||
Password string `json:"Password"`
|
||||
}
|
||||
|
||||
func Path(ctx *fiber.Ctx) error {
|
||||
var req PathReq
|
||||
if err := ctx.BodyParser(&req); err != nil {
|
||||
return ErrorResp(ctx, err, 400)
|
||||
}
|
||||
if model.AccountsCount() > 1 && req.Path == "" {
|
||||
return ctx.JSON(Resp{
|
||||
Code: 200,
|
||||
Msg: "folder",
|
||||
Data: model.GetAccountFiles(),
|
||||
})
|
||||
}
|
||||
account, path, driver, err := ParsePath(req.Path)
|
||||
if err != nil {
|
||||
return ErrorResp(ctx, err, 500)
|
||||
}
|
||||
file, files, err := driver.Path(path, account)
|
||||
if err != nil {
|
||||
return ErrorResp(ctx, err, 500)
|
||||
}
|
||||
if file != nil {
|
||||
return ctx.JSON(Resp{
|
||||
Code: 200,
|
||||
Msg: "file",
|
||||
Data: []*model.File{file},
|
||||
})
|
||||
} else {
|
||||
return ctx.JSON(Resp{
|
||||
Code: 200,
|
||||
Msg: "folder",
|
||||
Data: files,
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user