blossom: return code from Reject* functions because HTTP is stupid.

This commit is contained in:
fiatjaf 2024-10-28 17:30:07 -03:00
parent a893dc2d2c
commit 7f878121fc
2 changed files with 12 additions and 12 deletions

View File

@ -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
}
}

View File

@ -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 {