Add option for http mount

This commit is contained in:
Ben Sarmiento
2023-10-22 16:46:36 +02:00
parent 16d6bf4f81
commit 50075df13f
6 changed files with 300 additions and 7 deletions

43
internal/net/router.go Normal file
View File

@@ -0,0 +1,43 @@
package net
import (
"log"
"net/http"
"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/hashicorp/golang-lru/v2/expirable"
)
// Router creates a WebDAV router
func Router(mux *http.ServeMux, c config.ConfigInterface, t *torrent.TorrentManager, cache *expirable.LRU[string, string]) {
mux.HandleFunc("/http/", func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
intHttp.HandleDirectoryListing(w, r, t, c, cache)
default:
log.Println("Method not implemented", r.Method)
http.Error(w, "Method not implemented", http.StatusMethodNotAllowed)
}
})
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "PROPFIND":
dav.HandlePropfindRequest(w, r, t, c, cache)
case http.MethodGet:
dav.HandleGetRequest(w, r, t, c, cache)
case http.MethodOptions:
w.WriteHeader(http.StatusOK)
default:
log.Println("Method not implemented", r.Method)
http.Error(w, "Method not implemented", http.StatusMethodNotAllowed)
}
})
}