From 1ab44ab897daf0fefd3a6db7ac2634757d62e83f Mon Sep 17 00:00:00 2001 From: sudocarlos <122110235+sudocarlos@users.noreply.github.com> Date: Thu, 8 May 2025 09:29:26 -0400 Subject: [PATCH] blossom: implement BUD-05 without optimizations (#45) * blossom: implement BUD-05 without optimizations * blossom: add redirect function, handle /media with 307 redirect to /upload * blossome: remove duplicate /upload handle * blossom: add content-length header to handleHasBlob() * blossom: add content-type header to handleHasBlob() * blossom: remove blossomRedirect() and use http.Redirect() for handleMedia() instead --- blossom/handlers.go | 9 +++++++++ blossom/server.go | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/blossom/handlers.go b/blossom/handlers.go index 8dba1f5..4add124 100644 --- a/blossom/handlers.go +++ b/blossom/handlers.go @@ -227,6 +227,10 @@ func (bs BlossomServer) handleHasBlob(w http.ResponseWriter, r *http.Request) { blossomError(w, "file not found", 404) return } + w.Header().Set("Content-Length", strconv.Itoa(bd.Size)) + w.Header().Set("Accept-Ranges", "bytes") + w.Header().Set("Content-Type", bd.Type) + } func (bs BlossomServer) handleList(w http.ResponseWriter, r *http.Request) { @@ -453,5 +457,10 @@ func (bs BlossomServer) handleMirror(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(bd) } +func (bs BlossomServer) handleMedia(w http.ResponseWriter, r *http.Request) { + http.Redirect(w, r, "/upload", 307) + return +} + func (bs BlossomServer) handleNegentropy(w http.ResponseWriter, r *http.Request) { } diff --git a/blossom/server.go b/blossom/server.go index e5388f1..d031417 100644 --- a/blossom/server.go +++ b/blossom/server.go @@ -43,7 +43,10 @@ func New(rl *khatru.Relay, serviceURL string) *BlossomServer { return } } - + if r.URL.Path == "/media" { + bs.handleMedia(w, r) + return + } if r.URL.Path == "/mirror" && r.Method == "PUT" { bs.handleMirror(w, r) return