Skip to content

Commit

Permalink
✨ Extract folder
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Jan 16, 2022
1 parent e952f1c commit cfb51e9
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 15 deletions.
6 changes: 6 additions & 0 deletions drivers/base/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
1 change: 0 additions & 1 deletion drivers/native/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
13 changes: 7 additions & 6 deletions model/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
26 changes: 18 additions & 8 deletions model/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
{
Expand All @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions server/controllers/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit cfb51e9

Please sign in to comment.