mirror of https://github.com/Xhofe/alist
✨ link
parent
47bea7cc38
commit
a3f1553d40
|
@ -142,7 +142,7 @@ func initSettings() {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Key: "icon color",
|
Key: "icon color",
|
||||||
Value: "blue.400",
|
Value: "teal.300",
|
||||||
Type: "string",
|
Type: "string",
|
||||||
Description: "icon's color",
|
Description: "icon's color",
|
||||||
Group: model.PUBLIC,
|
Group: model.PUBLIC,
|
||||||
|
|
|
@ -65,6 +65,7 @@ type AliFile struct {
|
||||||
FileId string `json:"file_id"`
|
FileId string `json:"file_id"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
Category string `json:"category"`
|
||||||
ParentFileId string `json:"parent_file_id"`
|
ParentFileId string `json:"parent_file_id"`
|
||||||
UpdatedAt *time.Time `json:"updated_at"`
|
UpdatedAt *time.Time `json:"updated_at"`
|
||||||
Size int64 `json:"size"`
|
Size int64 `json:"size"`
|
||||||
|
@ -78,12 +79,19 @@ func AliToFile(file AliFile) *model.File {
|
||||||
Size: file.Size,
|
Size: file.Size,
|
||||||
UpdatedAt: file.UpdatedAt,
|
UpdatedAt: file.UpdatedAt,
|
||||||
Thumbnail: file.Thumbnail,
|
Thumbnail: file.Thumbnail,
|
||||||
|
Driver: "AliDrive",
|
||||||
}
|
}
|
||||||
if file.Type == "folder" {
|
if file.Type == "folder" {
|
||||||
f.Type = conf.FOLDER
|
f.Type = conf.FOLDER
|
||||||
} else {
|
} else {
|
||||||
f.Type = utils.GetFileType(file.FileExtension)
|
f.Type = utils.GetFileType(file.FileExtension)
|
||||||
}
|
}
|
||||||
|
if file.Category == "video" {
|
||||||
|
f.Type = conf.VIDEO
|
||||||
|
}
|
||||||
|
if file.Category == "image" {
|
||||||
|
f.Type = conf.IMAGE
|
||||||
|
}
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,6 +62,7 @@ func (n Native) Path(path string, account *model.Account) (*model.File, []*model
|
||||||
Size: f.Size(),
|
Size: f.Size(),
|
||||||
Type: 0,
|
Type: 0,
|
||||||
UpdatedAt: &time,
|
UpdatedAt: &time,
|
||||||
|
Driver: "Native",
|
||||||
}
|
}
|
||||||
if f.IsDir() {
|
if f.IsDir() {
|
||||||
file.Type = conf.FOLDER
|
file.Type = conf.FOLDER
|
||||||
|
@ -82,6 +83,7 @@ func (n Native) Path(path string, account *model.Account) (*model.File, []*model
|
||||||
Size: f.Size(),
|
Size: f.Size(),
|
||||||
Type: utils.GetFileType(filepath.Ext(f.Name())),
|
Type: utils.GetFileType(filepath.Ext(f.Name())),
|
||||||
UpdatedAt: &time,
|
UpdatedAt: &time,
|
||||||
|
Driver: "Native",
|
||||||
}
|
}
|
||||||
return file, nil, nil
|
return file, nil, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ type File struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Size int64 `json:"size"`
|
Size int64 `json:"size"`
|
||||||
Type int `json:"type"`
|
Type int `json:"type"`
|
||||||
|
Driver string `json:"driver"`
|
||||||
UpdatedAt *time.Time `json:"updated_at"`
|
UpdatedAt *time.Time `json:"updated_at"`
|
||||||
Thumbnail string `json:"thumbnail"`
|
Thumbnail string `json:"thumbnail"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,3 +56,30 @@ func Path(ctx *fiber.Ctx) error {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Link(ctx *fiber.Ctx) error {
|
||||||
|
var req PathReq
|
||||||
|
if err := ctx.BodyParser(&req); err != nil {
|
||||||
|
return ErrorResp(ctx, err, 400)
|
||||||
|
}
|
||||||
|
rawPath := req.Path
|
||||||
|
rawPath = utils.ParsePath(rawPath)
|
||||||
|
log.Debugf("down: %s",rawPath)
|
||||||
|
account, path, driver, err := ParsePath(rawPath)
|
||||||
|
if err != nil {
|
||||||
|
return ErrorResp(ctx, err, 500)
|
||||||
|
}
|
||||||
|
link, err := driver.Link(path, account)
|
||||||
|
if err != nil {
|
||||||
|
return ErrorResp(ctx, err, 500)
|
||||||
|
}
|
||||||
|
if account.Type == "Native" {
|
||||||
|
return SuccessResp(ctx, fiber.Map{
|
||||||
|
"url":"",
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
return SuccessResp(ctx,fiber.Map{
|
||||||
|
"url":link,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,6 +19,7 @@ func InitApiRouter(app *fiber.App) {
|
||||||
{
|
{
|
||||||
public.Post("/path", CheckAccount, Path)
|
public.Post("/path", CheckAccount, Path)
|
||||||
public.Get("/settings", GetSettingsPublic)
|
public.Get("/settings", GetSettingsPublic)
|
||||||
|
public.Post("/link", CheckAccount, Link)
|
||||||
}
|
}
|
||||||
|
|
||||||
admin := api.Group("/admin")
|
admin := api.Group("/admin")
|
||||||
|
|
Loading…
Reference in New Issue