feat(blossom): add redirect support for GET requests

This commit is contained in:
Anthony Accioly
2025-05-12 21:28:51 +01:00
committed by fiatjaf_
parent c5076b297d
commit 16eee5cffb
2 changed files with 17 additions and 2 deletions

View File

@@ -191,7 +191,21 @@ func (bs BlossomServer) handleGetBlob(w http.ResponseWriter, r *http.Request) {
var ext string
if len(spl) == 2 {
ext = "." + spl[1]
ext = spl[1]
}
if len(bs.RedirectGet) > 0 {
for _, redirect := range bs.RedirectGet {
redirectURL, code, err := redirect(r.Context(), hhash, ext)
if err == nil && redirectURL != "" {
// Not sure if browsers will cache redirects
// But it doesn't hurt anyway
w.Header().Set("ETag", hhash)
w.Header().Set("Cache-Control", "public, max-age=604800, immutable")
http.Redirect(w, r, redirectURL, code)
return
}
}
}
for _, lb := range bs.LoadBlob {
@@ -206,7 +220,7 @@ func (bs BlossomServer) handleGetBlob(w http.ResponseWriter, r *http.Request) {
}
w.Header().Set("ETag", hhash)
w.Header().Set("Cache-Control", "public, max-age=604800, immutable")
http.ServeContent(w, r, hhash+ext, t, reader)
http.ServeContent(w, r, hhash+"."+ext, t, reader)
return
}
}

View File

@@ -18,6 +18,7 @@ type BlossomServer struct {
LoadBlob []func(ctx context.Context, sha256 string) (io.ReadSeeker, error)
DeleteBlob []func(ctx context.Context, sha256 string) error
ReceiveReport []func(ctx context.Context, reportEvt *nostr.Event) error
RedirectGet []func(ctx context.Context, sha256 string, fileExtension string) (url string, code int, err error)
RejectUpload []func(ctx context.Context, auth *nostr.Event, size int, ext string) (bool, string, int)
RejectGet []func(ctx context.Context, auth *nostr.Event, sha256 string) (bool, string, int)