feat: image variants per image
This commit is contained in:
1 parent
f567866161
commit
951fef18ba
92 files changed
+8695
-413
No files matched your search
@@ -99,10 +99,11 @@ func StoredName(imagePath string) string {
|
||||
type Sort string
|
||||
|
||||
const (
|
||||
SortNewest Sort = "newest"
|
||||
SortOldest Sort = "oldest"
|
||||
SortName Sort = "name"
|
||||
SortLargest Sort = "largest"
|
||||
SortNewest Sort = "newest"
|
||||
SortOldest Sort = "oldest"
|
||||
SortName Sort = "name"
|
||||
SortLargest Sort = "largest"
|
||||
SortTotalSize Sort = "total_size"
|
||||
)
|
||||
|
||||
type Filter string
|
||||
@@ -113,13 +114,22 @@ const (
|
||||
FilterDuplicates Filter = "duplicates"
|
||||
)
|
||||
|
||||
type VariantsFilter string
|
||||
|
||||
const (
|
||||
VariantsAny VariantsFilter = ""
|
||||
VariantsWith VariantsFilter = "with"
|
||||
VariantsWithout VariantsFilter = "without"
|
||||
)
|
||||
|
||||
type ListQuery struct {
|
||||
Search string
|
||||
Hash string
|
||||
Filter Filter
|
||||
Sort Sort
|
||||
Limit int
|
||||
Cursor string
|
||||
Search string
|
||||
Hash string
|
||||
Filter Filter
|
||||
Variants VariantsFilter
|
||||
Sort Sort
|
||||
Limit int
|
||||
Cursor string
|
||||
}
|
||||
|
||||
func NewListQuery() ListQuery {
|
||||
@@ -133,7 +143,12 @@ func (q ListQuery) Validate() error {
|
||||
return ErrInvalidQuery
|
||||
}
|
||||
switch q.Sort {
|
||||
case SortNewest, SortOldest, SortName, SortLargest:
|
||||
case SortNewest, SortOldest, SortName, SortLargest, SortTotalSize:
|
||||
default:
|
||||
return ErrInvalidQuery
|
||||
}
|
||||
switch q.Variants {
|
||||
case VariantsAny, VariantsWith, VariantsWithout:
|
||||
default:
|
||||
return ErrInvalidQuery
|
||||
}
|
||||
@@ -175,6 +190,19 @@ func SortImages(images []Image, order Sort) {
|
||||
})
|
||||
}
|
||||
|
||||
func SortImagesByTotalSize(images []Image, totals map[string]VariantFileTotals) {
|
||||
totalOf := func(img Image) int64 {
|
||||
return img.Size + totals[StoredName(img.Path)].Bytes
|
||||
}
|
||||
sort.SliceStable(images, func(i, j int) bool {
|
||||
a, b := images[i], images[j]
|
||||
if totalOf(a) != totalOf(b) {
|
||||
return totalOf(a) > totalOf(b)
|
||||
}
|
||||
return a.ID < b.ID
|
||||
})
|
||||
}
|
||||
|
||||
type Counts struct {
|
||||
All int
|
||||
DuplicateGroups int
|
||||
|
||||
Reference in new issue
Block a user