Simple string sort on listing torrents
This commit is contained in:
@@ -38,17 +38,13 @@ func HandleListTorrents(directory string, torMgr *torrent.TorrentManager, log *l
|
||||
var buf bytes.Buffer
|
||||
buf.WriteString("<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">")
|
||||
buf.WriteString(dav.BaseDirectory(directory, ""))
|
||||
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(dav.Directory(tor.AccessKey, tor.LatestAdded))
|
||||
}
|
||||
buf.WriteString("</d:multistatus>")
|
||||
|
||||
Reference in New Issue
Block a user