Fix unrestrict issue

This commit is contained in:
Ben Sarmiento
2023-11-28 00:41:15 +01:00
parent c8334ecb3b
commit 3d380e468f
9 changed files with 131 additions and 68 deletions

View File

@@ -10,24 +10,23 @@ import (
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"
"go.uber.org/zap"
)
// Router creates a WebDAV router
func Router(mux *http.ServeMux, getfile *universal.GetFile, c config.ConfigInterface, t *torrent.TorrentManager, cache *expirable.LRU[string, string], log *zap.SugaredLogger) {
func Router(mux *http.ServeMux, getfile *universal.GetFile, c config.ConfigInterface, t *torrent.TorrentManager, log *zap.SugaredLogger) {
mux.HandleFunc("/http/", func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
requestPath := path.Clean(r.URL.Path)
if countNonEmptySegments(strings.Split(requestPath, "/")) > 3 {
getfile.HandleGetRequest(w, r, t, c, cache, log)
getfile.HandleGetRequest(w, r, t, c, log)
} else {
intHttp.HandleDirectoryListing(w, r, t, log)
}
case http.MethodHead:
universal.HandleHeadRequest(w, r, t, cache, log)
universal.HandleHeadRequest(w, r, t, log)
default:
log.Errorf("Request %s %s not supported yet", r.Method, r.URL.Path)
@@ -44,7 +43,7 @@ func Router(mux *http.ServeMux, getfile *universal.GetFile, c config.ConfigInter
dav.HandleDeleteRequest(w, r, t, log)
case http.MethodGet:
getfile.HandleGetRequest(w, r, t, c, cache, log)
getfile.HandleGetRequest(w, r, t, c, log)
case http.MethodOptions:
w.WriteHeader(http.StatusOK)