-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.go
47 lines (40 loc) · 1.21 KB
/
handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package dav
import (
"log/slog"
"net/http"
"github.com/go-chi/chi/v5"
"golang.org/x/net/webdav"
"github.com/Karaoke-Manager/karman/api/v1/dav/internal"
"github.com/Karaoke-Manager/karman/core/media"
"github.com/Karaoke-Manager/karman/core/song"
)
func init() {
// see https://de.wikipedia.org/wiki/WebDAV
chi.RegisterMethod("PROPFIND")
chi.RegisterMethod("PROPPATCH")
chi.RegisterMethod("MKCOL")
chi.RegisterMethod("COPY")
chi.RegisterMethod("MOVE")
chi.RegisterMethod("DELETE")
chi.RegisterMethod("LOCK")
chi.RegisterMethod("UNLOCK")
}
// Handler implements the /v1/dav endpoints.
type Handler struct {
wh *webdav.Handler
}
// NewHandler creates a new Handler instance using the specified services.
func NewHandler(logger *slog.Logger, songRepo song.Repository, songSvc song.Service, mediaStore media.Store) *Handler {
wh := &webdav.Handler{
// TODO: Make this configurable/dynamic
Prefix: "/v1/dav/",
FileSystem: internal.NewFlatFS(logger.With("log", "dav"), songRepo, songSvc, mediaStore),
LockSystem: webdav.NewMemLS(),
Logger: nil,
}
return &Handler{wh}
}
// ServeHTTP processes HTTP requests for h.
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.wh.ServeHTTP(w, r)
}