Consistent WebDav file sorting (#62)

* style: Sort webdav file lists by name
* style: Consistent sorting on the get torrents route
This commit is contained in:
Elias Benbourenane
2025-05-02 14:11:58 -04:00
committed by GitHub
parent 130433203f
commit ef820b5bf4
2 changed files with 15 additions and 4 deletions

View File

@@ -221,7 +221,17 @@ func (h *Handler) Stat(ctx context.Context, name string) (os.FileInfo, error) {
func (h *Handler) getFileInfos(torrent *types.Torrent) []os.FileInfo {
files := make([]os.FileInfo, 0, len(torrent.Files))
now := time.Now()
// Sort by file name since the order is lost when using the map
sortedFiles := make([]*types.File, 0, len(torrent.Files))
for _, file := range torrent.Files {
sortedFiles = append(sortedFiles, &file)
}
slices.SortFunc(sortedFiles, func(a, b *types.File) int {
return strings.Compare(a.Name, b.Name)
})
for _, file := range sortedFiles {
files = append(files, &FileInfo{
name: file.Name,
size: file.Size,