🔨 change path

This commit is contained in:
微凉
2021-10-28 12:37:31 +08:00
parent 55f683b12d
commit 98f7dffed9
5 changed files with 51 additions and 26 deletions

View File

@ -22,3 +22,10 @@ func Auth(ctx *fiber.Ctx) error {
}
return ctx.Next()
}
func CheckAccount(ctx *fiber.Ctx) error {
if model.AccountsCount() == 0 {
return ErrorResp(ctx,fmt.Errorf("no accounts,please add one first"),1001)
}
return ctx.Next()
}

View File

@ -27,12 +27,12 @@ func ParsePath(rawPath string) (*model.Account,string,drivers.Driver,error) {
break
default:
paths := strings.Split(rawPath,"/")
path = strings.Join(paths[1:],"/")
name = paths[0]
path = strings.Join(paths[2:],"/")
name = paths[1]
}
account,ok := model.GetAccount(name)
if !ok {
return nil,"",nil,fmt.Errorf("")
return nil,"",nil,fmt.Errorf("no [%s] account", name)
}
driver,ok := drivers.GetDriver(account.Type)
if !ok {

View File

@ -3,6 +3,7 @@ package server
import (
"github.com/Xhofe/alist/model"
"github.com/gofiber/fiber/v2"
"strings"
)
type PathReq struct {
@ -15,7 +16,10 @@ func Path(ctx *fiber.Ctx) error {
if err := ctx.BodyParser(&req); err != nil {
return ErrorResp(ctx, err, 400)
}
if model.AccountsCount() > 1 && req.Path == "" {
if !strings.HasPrefix(req.Path, "/") {
req.Path = "/"+req.Path
}
if model.AccountsCount() > 1 && req.Path == "/" {
return ctx.JSON(Resp{
Code: 200,
Msg: "folder",

View File

@ -1,15 +1,20 @@
package server
import "github.com/gofiber/fiber/v2"
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
)
func InitApiRouter(app *fiber.App) {
// TODO from settings
app.Use(cors.New())
app.Get("/d/*", Down)
public := app.Group("/api/public")
{
// TODO check accounts
public.Post("/path", Path)
public.Post("/path", CheckAccount, Path)
public.Get("/settings", GetSettingsPublic)
}