Finalize repair

This commit is contained in:
Ben Sarmiento
2023-10-26 03:29:13 +02:00
parent cc9616894a
commit 54ab801796
13 changed files with 500 additions and 517 deletions

View File

@@ -3,11 +3,14 @@ package net
import (
"log"
"net/http"
"path"
"strings"
"github.com/debridmediamanager.com/zurg/internal/config"
"github.com/debridmediamanager.com/zurg/internal/dav"
intHttp "github.com/debridmediamanager.com/zurg/internal/http"
"github.com/debridmediamanager.com/zurg/internal/torrent"
"github.com/debridmediamanager.com/zurg/internal/universal"
"github.com/hashicorp/golang-lru/v2/expirable"
)
@@ -16,10 +19,15 @@ func Router(mux *http.ServeMux, c config.ConfigInterface, t *torrent.TorrentMana
mux.HandleFunc("/http/", func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
intHttp.HandleDirectoryListing(w, r, t, c, cache)
requestPath := path.Clean(r.URL.Path)
if countNonEmptySegments(strings.Split(requestPath, "/")) > 3 {
universal.HandleGetRequest(w, r, t, c, cache)
} else {
intHttp.HandleDirectoryListing(w, r, t, c, cache)
}
case http.MethodHead:
intHttp.HandleHeadRequest(w, r, t, c, cache)
universal.HandleHeadRequest(w, r, t, c, cache)
default:
log.Println("Method not implemented", r.Method)
@@ -33,7 +41,7 @@ func Router(mux *http.ServeMux, c config.ConfigInterface, t *torrent.TorrentMana
dav.HandlePropfindRequest(w, r, t, c, cache)
case http.MethodGet:
dav.HandleGetRequest(w, r, t, c, cache)
universal.HandleGetRequest(w, r, t, c, cache)
case http.MethodOptions:
w.WriteHeader(http.StatusOK)
@@ -44,3 +52,13 @@ func Router(mux *http.ServeMux, c config.ConfigInterface, t *torrent.TorrentMana
}
})
}
func countNonEmptySegments(urlSegments []string) int {
count := 0
for _, s := range urlSegments {
if s != "" {
count++
}
}
return count
}