clear cache

pull/548/head
微凉 2021-11-01 22:42:24 +08:00
parent 6313939e8c
commit 5c2ce5b442
6 changed files with 49 additions and 11 deletions

View File

@ -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, ",")
}
}

View File

@ -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
}

View File

@ -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"`
}

15
server/cache.go Normal file
View File

@ -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)
}
}

View File

@ -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{

View File

@ -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)
}
}