mirror of
https://github.com/fiatjaf/khatru.git
synced 2025-03-17 21:32:55 +01:00
blossom: return code from Reject* functions because HTTP is stupid.
This commit is contained in:
parent
a893dc2d2c
commit
7f878121fc
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user