2021-10-26 14:28:37 +00:00
|
|
|
package model
|
|
|
|
|
2021-11-23 08:09:42 +00:00
|
|
|
import (
|
|
|
|
"sort"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
)
|
2021-10-26 14:28:37 +00:00
|
|
|
|
|
|
|
type File struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Size int64 `json:"size"`
|
|
|
|
Type int `json:"type"`
|
2021-10-30 16:36:17 +00:00
|
|
|
Driver string `json:"driver"`
|
2021-10-26 14:28:37 +00:00
|
|
|
UpdatedAt *time.Time `json:"updated_at"`
|
2021-10-29 16:35:29 +00:00
|
|
|
Thumbnail string `json:"thumbnail"`
|
2021-11-01 14:42:24 +00:00
|
|
|
Url string `json:"url"`
|
2021-11-23 08:09:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func SortFiles(files []File, account *Account) {
|
|
|
|
if account.OrderBy == "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
sort.Slice(files, func(i, j int) bool {
|
|
|
|
switch account.OrderBy {
|
|
|
|
case "name":
|
|
|
|
{
|
|
|
|
c := strings.Compare(files[i].Name, files[j].Name)
|
|
|
|
if account.OrderDirection == "DESC" {
|
|
|
|
return c >= 0
|
|
|
|
}
|
|
|
|
return c <= 0
|
|
|
|
}
|
|
|
|
case "size":
|
|
|
|
{
|
|
|
|
if account.OrderDirection == "DESC" {
|
|
|
|
return files[i].Size >= files[j].Size
|
|
|
|
}
|
|
|
|
return files[i].Size <= files[j].Size
|
|
|
|
}
|
|
|
|
case "updated_at":
|
|
|
|
if account.OrderDirection == "DESC" {
|
|
|
|
return files[i].UpdatedAt.After(*files[j].UpdatedAt)
|
|
|
|
}
|
|
|
|
return files[i].UpdatedAt.Before(*files[j].UpdatedAt)
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
}
|