Extract folder

pull/548/head
微凉 2022-01-16 16:38:41 +08:00
parent e952f1c243
commit cfb51e9f80
5 changed files with 32 additions and 15 deletions

View File

@ -119,6 +119,12 @@ func GetDrivers() map[string][]Item {
Label: "down_proxy_url", Label: "down_proxy_url",
Type: TypeString, Type: TypeString,
}, },
{
Name: "extract_folder",
Label: "extract_folder",
Values: "front,back",
Type: TypeSelect,
},
}, res[k]...) }, res[k]...)
if v.Config().ApiProxy { if v.Config().ApiProxy {
res[k] = append([]Item{ res[k] = append([]Item{

View File

@ -110,7 +110,6 @@ func (driver Native) Files(path string, account *model.Account) ([]model.File, e
} }
files = append(files, file) files = append(files, file)
} }
model.SortFiles(files, account)
return files, nil return files, nil
} }

View File

@ -42,6 +42,7 @@ type Account struct {
AccessKey string `json:"access_key"` AccessKey string `json:"access_key"`
AccessSecret string `json:"access_secret"` AccessSecret string `json:"access_secret"`
CustomHost string `json:"custom_host"` CustomHost string `json:"custom_host"`
ExtractFolder string `json:"extract_folder"`
} }
var accountsMap = map[string]Account{} var accountsMap = map[string]Account{}

View File

@ -25,14 +25,6 @@ func SortFiles(files []File, account *Account) {
return return
} }
sort.Slice(files, func(i, j int) bool { 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 { switch account.OrderBy {
case "name": 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 { func (f File) GetSize() uint64 {
return uint64(f.Size) return uint64(f.Size)
} }

View File

@ -164,6 +164,7 @@ func Path(c *gin.Context) {
if driver.Config().LocalSort { if driver.Config().LocalSort {
model.SortFiles(files, account) model.SortFiles(files, account)
} }
model.ExtractFolder(files, account)
total, files := Pagination(files, &req) total, files := Pagination(files, &req)
c.JSON(200, common.Resp{ c.JSON(200, common.Resp{
Code: 200, Code: 200,