From 3c12b92e6140293c0d60542405dd510a5bf516db Mon Sep 17 00:00:00 2001 From: Ben Sarmiento Date: Thu, 23 Nov 2023 00:34:15 +0100 Subject: [PATCH] Skip in progress torrents when listing --- internal/dav/listing.go | 3 +++ internal/http/listing.go | 18 ++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/internal/dav/listing.go b/internal/dav/listing.go index 5ffd715..c1c7ef6 100644 --- a/internal/dav/listing.go +++ b/internal/dav/listing.go @@ -72,6 +72,9 @@ func handleListTorrents(w http.ResponseWriter, requestPath string, t *torrent.To var allTorrents []*torrent.Torrent torrents.IterCb(func(_ string, tor *torrent.Torrent) { + if tor.InProgress() { + return + } allTorrents = append(allTorrents, tor) }) sort.Slice(allTorrents, func(i, j int) bool { diff --git a/internal/http/listing.go b/internal/http/listing.go index 4073750..6f1baa4 100644 --- a/internal/http/listing.go +++ b/internal/http/listing.go @@ -71,10 +71,20 @@ func handleListOfTorrents(requestPath string, t *torrent.TorrentManager) (*strin } htmlDoc := "
    " - accessKeys := torrents.Keys() - sort.Strings(accessKeys) - for _, accessKey := range accessKeys { - htmlDoc = htmlDoc + fmt.Sprintf("
  1. %s
  2. ", filepath.Join(requestPath, url.PathEscape(accessKey)), accessKey) + + var allTorrents []*torrent.Torrent + torrents.IterCb(func(_ string, tor *torrent.Torrent) { + if tor.InProgress() { + return + } + allTorrents = append(allTorrents, tor) + }) + sort.Slice(allTorrents, func(i, j int) bool { + return allTorrents[i].AccessKey < allTorrents[j].AccessKey + }) + + for _, tor := range allTorrents { + htmlDoc = htmlDoc + fmt.Sprintf("
  3. %s
  4. ", filepath.Join(requestPath, url.PathEscape(tor.AccessKey)), tor.AccessKey) } return &htmlDoc, nil }