42 lines
884 B
Go
42 lines
884 B
Go
package dav
|
|
|
|
import (
|
|
"fmt"
|
|
"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)
|
|
}
|
|
|
|
fmt.Println("config version", c.GetDirectories())
|
|
|
|
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)
|
|
}
|
|
})
|
|
}
|