diff --git a/drivers/base/driver.go b/drivers/base/driver.go index d88a47cf..d5b7e4b4 100644 --- a/drivers/base/driver.go +++ b/drivers/base/driver.go @@ -119,6 +119,12 @@ func GetDrivers() map[string][]Item { Label: "down_proxy_url", Type: TypeString, }, + { + Name: "extract_folder", + Label: "extract_folder", + Values: "front,back", + Type: TypeSelect, + }, }, res[k]...) if v.Config().ApiProxy { res[k] = append([]Item{ diff --git a/drivers/native/driver.go b/drivers/native/driver.go index 7bcbe079..0529226e 100644 --- a/drivers/native/driver.go +++ b/drivers/native/driver.go @@ -110,7 +110,6 @@ func (driver Native) Files(path string, account *model.Account) ([]model.File, e } files = append(files, file) } - model.SortFiles(files, account) return files, nil } diff --git a/model/account.go b/model/account.go index 0f0f3436..f217bc5e 100644 --- a/model/account.go +++ b/model/account.go @@ -36,12 +36,13 @@ type Account struct { DownProxyUrl string `json:"down_proxy_url"` // 用于中转下载服务的URL 两处 1. path请求中返回的链接 2. down下载时进行302 APIProxyUrl string `json:"api_proxy_url"` // 用于中转api的地址 // for s3 - Bucket string `json:"bucket"` - Endpoint string `json:"endpoint"` - Region string `json:"region"` - AccessKey string `json:"access_key"` - AccessSecret string `json:"access_secret"` - CustomHost string `json:"custom_host"` + Bucket string `json:"bucket"` + Endpoint string `json:"endpoint"` + Region string `json:"region"` + AccessKey string `json:"access_key"` + AccessSecret string `json:"access_secret"` + CustomHost string `json:"custom_host"` + ExtractFolder string `json:"extract_folder"` } var accountsMap = map[string]Account{} diff --git a/model/file.go b/model/file.go index c5a8e4b7..eb0cb0b8 100644 --- a/model/file.go +++ b/model/file.go @@ -25,14 +25,6 @@ func SortFiles(files []File, account *Account) { return } sort.Slice(files, func(i, j int) bool { - if files[i].IsDir() || files[j].IsDir() { - if !files[i].IsDir() { - return false - } - if !files[j].IsDir() { - return true - } - } switch account.OrderBy { case "name": { @@ -59,6 +51,24 @@ func SortFiles(files []File, account *Account) { }) } +func ExtractFolder(files []File, account *Account) { + if account.ExtractFolder == "" { + return + } + front := account.ExtractFolder == "front" + sort.Slice(files, func(i, j int) bool { + if files[i].IsDir() || files[j].IsDir() { + if !files[i].IsDir() { + return !front + } + if !files[j].IsDir() { + return front + } + } + return false + }) +} + func (f File) GetSize() uint64 { return uint64(f.Size) } diff --git a/server/controllers/path.go b/server/controllers/path.go index 772b1349..14f411ed 100644 --- a/server/controllers/path.go +++ b/server/controllers/path.go @@ -164,6 +164,7 @@ func Path(c *gin.Context) { if driver.Config().LocalSort { model.SortFiles(files, account) } + model.ExtractFolder(files, account) total, files := Pagination(files, &req) c.JSON(200, common.Resp{ Code: 200,