diff --git a/bootstrap/model.go b/bootstrap/model.go index a5bca0b2..b2d8f4cf 100644 --- a/bootstrap/model.go +++ b/bootstrap/model.go @@ -148,11 +148,23 @@ func initSettings() { Group: model.PUBLIC, }, { - Key: "text types", - Value: "txt,htm,html,xml,java,properties,sql,js,md,json,conf,ini,vue,php,py,bat,gitignore,yml,go,sh,c,cpp,h,hpp", - Type: "string", + Key: "text types", + Value: "txt,htm,html,xml,java,properties,sql,js,md,json,conf,ini,vue,php,py,bat,gitignore,yml,go,sh,c,cpp,h,hpp", + Type: "string", Description: "text type extensions", }, + { + Key: "readme file", + Value: "hide", + Type: "string", + Description: "hide readme file? (show/hide)", + }, + { + Key: "music cover", + Value: "https://store.heytapimage.com/cdo-portal/feedback/202110/30/d43c41c5d257c9bc36366e310374fb19.png", + Type: "string", + Description: "music cover image", + }, }, } for k, v := range settingsMap { @@ -165,7 +177,7 @@ func initSettings() { } } textTypes, err := model.GetSettingByKey("text types") - if err==nil{ - conf.TextTypes = strings.Split(textTypes.Value,",") + if err == nil { + conf.TextTypes = strings.Split(textTypes.Value, ",") } } diff --git a/drivers/alidrive.go b/drivers/alidrive.go index 7b0d664b..90c3d957 100644 --- a/drivers/alidrive.go +++ b/drivers/alidrive.go @@ -37,7 +37,7 @@ func (a AliDrive) Preview(path string, account *model.Account) (interface{}, err var url string req := Json{ "drive_id": account.DriveId, - "file_id": file.FileId, + "file_id": file.FileId, } switch file.Category { case "doc": @@ -60,7 +60,7 @@ func (a AliDrive) Preview(path string, account *model.Account) (interface{}, err return nil, err } if e.Code != "" { - return nil, fmt.Errorf("%s",e.Message) + return nil, fmt.Errorf("%s", e.Message) } return resp, nil } @@ -119,6 +119,7 @@ func AliToFile(file AliFile) *model.File { UpdatedAt: file.UpdatedAt, Thumbnail: file.Thumbnail, Driver: "AliDrive", + Url: file.Url, } if file.Type == "folder" { f.Type = conf.FOLDER @@ -158,7 +159,7 @@ func (a AliDrive) GetFiles(fileId string, account *model.Account) ([]AliFile, er "order_direction": account.OrderDirection, "parent_file_id": fileId, "video_thumbnail_process": "video/snapshot,t_0,f_jpg,ar_auto,w_300", - //"url_expire_sec": 1600, + "url_expire_sec": 14400, })).Post("https://api.aliyundrive.com/v2/file/list") if err != nil { return nil, err @@ -226,6 +227,11 @@ func (a AliDrive) Path(path string, account *model.Account) (*model.File, []*mod if file.Name == name { found = true if file.Type == "file" { + url,err := a.Link(path,account) + if err != nil { + return nil, nil, err + } + file.Url = url return AliToFile(file), nil, nil } else { fileId = file.FileId @@ -251,7 +257,7 @@ func (a AliDrive) Path(path string, account *model.Account) (*model.File, []*mod } func (a AliDrive) Link(path string, account *model.Account) (string, error) { - file, err := a.GetFile(path, account) + file, err := a.GetFile(utils.ParsePath(path), account) if err != nil { return "", err } diff --git a/model/file.go b/model/file.go index 6123ccf4..b8fd297a 100644 --- a/model/file.go +++ b/model/file.go @@ -9,4 +9,5 @@ type File struct { Driver string `json:"driver"` UpdatedAt *time.Time `json:"updated_at"` Thumbnail string `json:"thumbnail"` -} + Url string `json:"url"` +} \ No newline at end of file diff --git a/server/cache.go b/server/cache.go new file mode 100644 index 00000000..e74c80f2 --- /dev/null +++ b/server/cache.go @@ -0,0 +1,15 @@ +package server + +import ( + "github.com/Xhofe/alist/conf" + "github.com/gofiber/fiber/v2" +) + +func ClearCache(ctx *fiber.Ctx) error { + err := conf.Cache.Clear(conf.Ctx) + if err != nil { + return ErrorResp(ctx,err,500) + }else { + return SuccessResp(ctx) + } +} \ No newline at end of file diff --git a/server/path.go b/server/path.go index 018094fc..b561aa10 100644 --- a/server/path.go +++ b/server/path.go @@ -43,6 +43,9 @@ func Path(ctx *fiber.Ctx) error { return ErrorResp(ctx, err, 500) } if file != nil { + if account.Type == "Native" { + file.Url = fmt.Sprintf("%s://%s/p%s",ctx.Protocol(),ctx.Hostname(),req.Path) + } return ctx.JSON(Resp{ Code: 200, Message: "file", @@ -75,7 +78,7 @@ func Link(ctx *fiber.Ctx) error { } if account.Type == "Native" { return SuccessResp(ctx, fiber.Map{ - "url":"", + "url":fmt.Sprintf("%s://%s/p%s",ctx.Protocol(),ctx.Hostname(),rawPath), }) } else { return SuccessResp(ctx,fiber.Map{ diff --git a/server/router.go b/server/router.go index 9ed7a5c8..64ec10c7 100644 --- a/server/router.go +++ b/server/router.go @@ -33,5 +33,6 @@ func InitApiRouter(app *fiber.App) { admin.Get("/accounts", GetAccounts) admin.Delete("/account", DeleteAccount) admin.Get("/drivers", GetDrivers) + admin.Get("/clear_cache",ClearCache) } }