feat: complete remediation phase 3
Some checks failed
Automated Container Build / build-and-push (push) Failing after 15s

This commit is contained in:
Elijah 2026-05-26 14:23:50 -07:00
parent 0221e277a6
commit 6772ba8c43
10 changed files with 63 additions and 20 deletions

View file

@ -21,6 +21,16 @@ import (
"golang.org/x/net/webdav"
)
type statusCapture struct {
http.ResponseWriter
statusCode int
}
func (sc *statusCapture) WriteHeader(code int) {
sc.statusCode = code
sc.ResponseWriter.WriteHeader(code)
}
type WebDAVHandler struct {
Handler *webdav.Handler
DB *database.DB
@ -117,11 +127,11 @@ func (h *WebDAVHandler) Handle(c *fiber.Ctx) error {
// Adapt Fiber's FastHTTP to standard net/http for the WebDAV handler
fasthttpadaptor.NewFastHTTPHandlerFunc(func(w http.ResponseWriter, r *http.Request) {
relPath := strings.TrimPrefix(r.URL.Path, "/webdav")
// Native WebDAV handles overwriting automatically
h.Handler.ServeHTTP(w, r)
// If it was a PUT request, we should sync it with our DB (checksum, size, etc.)
if r.Method == "PUT" && r.Response != nil && r.Response.StatusCode >= 200 && r.Response.StatusCode < 300 {
capture := &statusCapture{ResponseWriter: w, statusCode: 200}
h.Handler.ServeHTTP(capture, r)
if r.Method == "PUT" && capture.statusCode >= 200 && capture.statusCode < 300 {
h.syncToDB(relPath)
}
})(c.Context())