refactor
This commit is contained in:
@@ -44,7 +44,7 @@ func HandleHeadRequest(w http.ResponseWriter, r *http.Request, t *torrent.Torren
|
||||
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, segments)
|
||||
http.Error(w, "Cannot find file", http.StatusNotFound)
|
||||
@@ -115,7 +115,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)
|
||||
@@ -172,17 +172,6 @@ func getFile(torrents []torrent.Torrent, filename, fragment string) (*torrent.To
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func HandleDirectoryListing(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager, c config.ConfigInterface, cache *expirable.LRU[string, string]) {
|
||||
requestPath := path.Clean(r.URL.Path)
|
||||
|
||||
@@ -258,7 +247,7 @@ func handleSingleTorrent(requestPath string, w http.ResponseWriter, r *http.Requ
|
||||
directory := path.Base(fullDir)
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user