mirror of
https://github.com/aljazceru/khatru.git
synced 2026-02-01 11:14:20 +01:00
feat(blossom): add redirect support for GET requests
This commit is contained in:
committed by
fiatjaf_
parent
c5076b297d
commit
16eee5cffb
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user