From 7f878121fc98669b91f488f12ea5c2fe723428f0 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Mon, 28 Oct 2024 17:30:07 -0300 Subject: [PATCH] blossom: return code from Reject* functions because HTTP is stupid. --- blossom/handlers.go | 16 ++++++++-------- blossom/server.go | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/blossom/handlers.go b/blossom/handlers.go index d738e25..45d4f02 100644 --- a/blossom/handlers.go +++ b/blossom/handlers.go @@ -43,9 +43,9 @@ func (bs BlossomServer) handleUpload(w http.ResponseWriter, r *http.Request) { // run the reject hooks for _, ru := range bs.RejectUpload { - reject, reason := ru(r.Context(), auth, ft.Extension) + reject, reason, code := ru(r.Context(), auth, ft.Extension) if reject { - http.Error(w, reason, 403) + http.Error(w, reason, code) return } } @@ -130,9 +130,9 @@ func (bs BlossomServer) handleGetBlob(w http.ResponseWriter, r *http.Request) { } for _, rg := range bs.RejectGet { - reject, reason := rg(r.Context(), auth, hhash) + reject, reason, code := rg(r.Context(), auth, hhash) if reject { - http.Error(w, reason, 401) + http.Error(w, reason, code) return } } @@ -197,9 +197,9 @@ func (bs BlossomServer) handleList(w http.ResponseWriter, r *http.Request) { pubkey := r.URL.Path[6:] for _, rl := range bs.RejectList { - reject, reason := rl(r.Context(), auth, pubkey) + reject, reason, code := rl(r.Context(), auth, pubkey) if reject { - http.Error(w, reason, 401) + http.Error(w, reason, code) return } } @@ -244,9 +244,9 @@ func (bs BlossomServer) handleDelete(w http.ResponseWriter, r *http.Request) { } for _, rd := range bs.RejectDelete { - reject, reason := rd(r.Context(), auth, hhash) + reject, reason, code := rd(r.Context(), auth, hhash) if reject { - http.Error(w, reason, 401) + http.Error(w, reason, code) return } } diff --git a/blossom/server.go b/blossom/server.go index 651afc2..837bccf 100644 --- a/blossom/server.go +++ b/blossom/server.go @@ -17,10 +17,10 @@ type BlossomServer struct { LoadBlob []func(ctx context.Context, sha256 string) ([]byte, error) DeleteBlob []func(ctx context.Context, sha256 string) error - RejectUpload []func(ctx context.Context, auth *nostr.Event, ext string) (bool, string) - RejectGet []func(ctx context.Context, auth *nostr.Event, sha256 string) (bool, string) - RejectList []func(ctx context.Context, auth *nostr.Event, pubkey string) (bool, string) - RejectDelete []func(ctx context.Context, auth *nostr.Event, sha256 string) (bool, string) + RejectUpload []func(ctx context.Context, auth *nostr.Event, ext string) (bool, string, int) + RejectGet []func(ctx context.Context, auth *nostr.Event, sha256 string) (bool, string, int) + RejectList []func(ctx context.Context, auth *nostr.Event, pubkey string) (bool, string, int) + RejectDelete []func(ctx context.Context, auth *nostr.Event, sha256 string) (bool, string, int) } func New(rl *khatru.Relay, serviceURL string) *BlossomServer {