Files
zurg/internal/dav/router.go
2023-10-18 21:09:25 +02:00

39 lines
825 B
Go

package dav
import (
"log"
"net/http"
"os"
"github.com/debridmediamanager.com/zurg/internal/config"
"github.com/debridmediamanager.com/zurg/internal/torrent"
)
// Router creates a WebDAV router
func Router(mux *http.ServeMux) {
c, err := config.LoadZurgConfig("./config.yml")
if err != nil {
log.Panicf("Config failed to load: %v", err)
}
t := torrent.NewTorrentManager(os.Getenv("RD_TOKEN"), c)
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "PROPFIND":
HandlePropfindRequest(w, r, t, c)
case http.MethodGet:
HandleGetRequest(w, r, t)
// default return
case http.MethodOptions:
w.WriteHeader(http.StatusOK)
default:
log.Println("Method not implemented")
http.Error(w, "Method not implemented", http.StatusMethodNotAllowed)
}
})
}