47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
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)
|
|
|
|
case http.MethodHead:
|
|
intHttp.HandleHeadRequest(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, r.URL.Path)
|
|
http.Error(w, "Method not implemented", http.StatusMethodNotAllowed)
|
|
}
|
|
})
|
|
}
|