Last batch of optimizations

This commit is contained in:
Ben Sarmiento
2023-11-19 02:55:19 +01:00
parent ae635799f8
commit 81d1df9bb5
6 changed files with 19 additions and 17 deletions

View File

@@ -9,12 +9,11 @@ import (
"sort"
"strings"
"github.com/debridmediamanager.com/zurg/internal/config"
"github.com/debridmediamanager.com/zurg/internal/torrent"
"github.com/debridmediamanager.com/zurg/pkg/logutil"
)
func HandleDirectoryListing(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager, c config.ConfigInterface) {
func HandleDirectoryListing(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager) {
log := logutil.NewLogger().Named("http")
requestPath := path.Clean(r.URL.Path)
@@ -25,7 +24,7 @@ func HandleDirectoryListing(w http.ResponseWriter, r *http.Request, t *torrent.T
filteredSegments := removeEmptySegments(strings.Split(requestPath, "/"))
switch {
case len(filteredSegments) == 1:
output, err = handleRoot(c)
output, err = handleRoot(t)
case len(filteredSegments) == 2:
output, err = handleListOfTorrents(requestPath, t)
case len(filteredSegments) == 3:
@@ -52,10 +51,11 @@ func HandleDirectoryListing(w http.ResponseWriter, r *http.Request, t *torrent.T
}
}
func handleRoot(c config.ConfigInterface) (*string, error) {
htmlDoc := "<ul>"
for _, directory := range c.GetDirectories() {
func handleRoot(t *torrent.TorrentManager) (*string, error) {
htmlDoc := "<ol>"
directories := t.DirectoryMap.Keys()
sort.Strings(directories)
for _, directory := range directories {
directoryPath := url.PathEscape(directory)
htmlDoc += fmt.Sprintf("<li><a href=\"/http/%s/\">%s</a></li>", directoryPath, directory)
}