This commit is contained in:
Ben Sarmiento
2023-10-24 04:53:26 +02:00
parent 21cbb16b88
commit 03db4b0c00
4 changed files with 5 additions and 31 deletions

View File

@@ -38,7 +38,7 @@ func HandleGetRequest(w http.ResponseWriter, r *http.Request, t *torrent.Torrent
torrentName := segments[len(segments)-2]
filename := segments[len(segments)-1]
torrents := findAllTorrentsWithName(t, baseDirectory, torrentName)
torrents := t.FindAllTorrentsWithName(baseDirectory, torrentName)
if torrents == nil {
log.Println("Cannot find torrent", torrentName)
http.Error(w, "Cannot find file", http.StatusNotFound)

View File

@@ -92,7 +92,7 @@ func handleSingleTorrent(requestPath string, w http.ResponseWriter, r *http.Requ
directory := path.Dir(requestPath)
torrentName := path.Base(requestPath)
sameNameTorrents := findAllTorrentsWithName(t, directory, torrentName)
sameNameTorrents := t.FindAllTorrentsWithName(directory, torrentName)
if len(sameNameTorrents) == 0 {
return nil, fmt.Errorf("cannot find directory when generating single torrent: %s", requestPath)
}

View File

@@ -2,10 +2,7 @@ package dav
import (
"log"
"strings"
"time"
"github.com/debridmediamanager.com/zurg/internal/torrent"
)
// convertRFC3339toRFC1123 converts a date from RFC3339 to RFC1123
@@ -17,15 +14,3 @@ func convertRFC3339toRFC1123(input string) string {
}
return t.Format("Mon, 02 Jan 2006 15:04:05 GMT")
}
// findAllTorrentsWithName finds all torrents in a given directory with a given name
func findAllTorrentsWithName(t *torrent.TorrentManager, directory, torrentName string) []torrent.Torrent {
matchingTorrents := make([]torrent.Torrent, 0, 10)
torrents := t.GetByDirectory(directory)
for i := range torrents {
if torrents[i].Name == torrentName || strings.HasPrefix(torrents[i].Name, torrentName) {
matchingTorrents = append(matchingTorrents, torrents[i])
}
}
return matchingTorrents
}