Last batch of optimizations
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user