mirror of https://github.com/Xhofe/alist
🔨 change path
parent
55f683b12d
commit
98f7dffed9
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"github.com/Xhofe/alist/conf"
|
||||
"github.com/Xhofe/alist/model"
|
||||
"github.com/Xhofe/alist/utils"
|
||||
"github.com/go-resty/resty/v2"
|
||||
"github.com/robfig/cron/v3"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
@ -29,39 +30,47 @@ type AliRespError struct {
|
|||
}
|
||||
|
||||
type AliFile struct {
|
||||
AliRespError
|
||||
DriveId string `json:"drive_id"`
|
||||
CreatedAt *time.Time `json:"created_at"`
|
||||
DomainId string `json:"domain_id"`
|
||||
EncryptMode string `json:"encrypt_mode"`
|
||||
FileExtension string `json:"file_extension"`
|
||||
FileId string `json:"file_id"`
|
||||
Hidden bool `json:"hidden"`
|
||||
Name string `json:"name"`
|
||||
ParentFileId string `json:"parent_file_id"`
|
||||
Starred bool `json:"starred"`
|
||||
Status string `json:"status"`
|
||||
Type string `json:"type"`
|
||||
UpdatedAt *time.Time `json:"updated_at"`
|
||||
Category string `json:"category"`
|
||||
ContentHash string `json:"content_hash"`
|
||||
ContentHashName string `json:"content_hash_name"`
|
||||
ContentType string `json:"content_type"`
|
||||
Crc64Hash string `json:"crc_64_hash"`
|
||||
DownloadUrl string `json:"download_url"`
|
||||
PunishFlag int64 `json:"punish_flag"`
|
||||
Size int64 `json:"size"`
|
||||
Thumbnail string `json:"thumbnail"`
|
||||
//Thumbnail string `json:"thumbnail"`
|
||||
Url string `json:"url"`
|
||||
ImageMediaMetadata map[string]interface{} `json:"image_media_metadata"`
|
||||
}
|
||||
|
||||
func AliToFile(file AliFile) *model.File {
|
||||
return &model.File{
|
||||
Name: file.Name,
|
||||
Size: file.Size,
|
||||
Type: utils.GetFileType(file.FileExtension),
|
||||
UpdatedAt: file.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
// path: /aaa/bbb
|
||||
func (a AliDrive) Path(path string, account *model.Account) (*model.File, []*model.File, error) {
|
||||
_, err := conf.Cache.Get(conf.Ctx, path)
|
||||
cache, err := conf.Cache.Get(conf.Ctx, path)
|
||||
if err == nil {
|
||||
// return
|
||||
file,ok := cache.(AliFile)
|
||||
if ok {
|
||||
return AliToFile(file), nil, nil
|
||||
}else {
|
||||
files,_ := cache.([]AliFile)
|
||||
res := make([]*model.File,0)
|
||||
for _,file = range files{
|
||||
res = append(res, AliToFile(file))
|
||||
}
|
||||
return nil, res, nil
|
||||
}
|
||||
}else {
|
||||
if path != "/" {
|
||||
|
||||
}
|
||||
}
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
}
|
|
@ -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 {
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue