MediaFile.GetRelatedFiles() now returns shorter filenames first

This commit is contained in:
Michael Mayer 2018-09-18 20:03:43 +02:00
parent 0c39f51a86
commit 4119170587
2 changed files with 26 additions and 1 deletions

View file

@ -17,6 +17,7 @@ import (
"net/http"
"os"
"path/filepath"
"sort"
"strings"
"time"
)
@ -258,7 +259,7 @@ func (m *MediaFile) GetEditedFilename() (result string) {
return result
}
func (m *MediaFile) GetRelatedFiles() (result []*MediaFile, mainFile *MediaFile, err error) {
func (m *MediaFile) GetRelatedFiles() (result MediaFiles, mainFile *MediaFile, err error) {
baseFilename := m.GetCanonicalNameFromFileWithDirectory()
matches, err := filepath.Glob(baseFilename + "*")
@ -289,6 +290,8 @@ func (m *MediaFile) GetRelatedFiles() (result []*MediaFile, mainFile *MediaFile,
result = append(result, resultFile)
}
sort.Sort(result)
return result, mainFile, nil
}

View file

@ -0,0 +1,22 @@
package photoprism
type MediaFiles []*MediaFile
func (f MediaFiles) Len() int {
return len(f)
}
func (f MediaFiles) Less(i, j int) bool {
fileName1 := f[i].GetFilename()
fileName2 := f[j].GetFilename()
if len(fileName1) == len(fileName2) {
return fileName1 < fileName2
} else {
return len(fileName1) < len(fileName2)
}
}
func (f MediaFiles) Swap(i, j int) {
f[i], f[j] = f[j], f[i]
}