Simple string sort on listing torrents

This commit is contained in:
Ben Sarmiento
2023-12-12 00:38:17 +01:00
parent ed903c8943
commit 2a1bc59300
6 changed files with 26 additions and 28 deletions

View File

@@ -37,17 +37,13 @@ func HandleListTorrents(directory string, torMgr *torrent.TorrentManager, log *l
var buf bytes.Buffer
buf.WriteString("<ol>")
var allTorrents []*torrent.Torrent
torrents.IterCb(func(_ string, tor *torrent.Torrent) {
if tor.AllInProgress() {
return
torrentNames := torrents.Keys()
sort.Strings(torrentNames)
for _, torrentName := range torrentNames {
tor, ok := torrents.Get(torrentName)
if !ok || tor.AllInProgress() {
continue
}
allTorrents = append(allTorrents, tor)
})
sort.Slice(allTorrents, func(i, j int) bool {
return allTorrents[i].AccessKey < allTorrents[j].AccessKey
})
for _, tor := range allTorrents {
buf.WriteString(fmt.Sprintf("<li><a href=\"/http/%s/\">%s</a></li>", filepath.Join(directory, url.PathEscape(tor.AccessKey)), tor.AccessKey))
}
return buf.Bytes(), nil