diff --git a/blossom/handlers.go b/blossom/handlers.go index 83dd815..224a8ca 100644 --- a/blossom/handlers.go +++ b/blossom/handlers.go @@ -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 } } diff --git a/blossom/server.go b/blossom/server.go index d031417..848c9ab 100644 --- a/blossom/server.go +++ b/blossom/server.go @@ -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)