From 90697ad3d35f4dd1fc73aa1acb91f9f14f834e62 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Mon, 27 Nov 2023 00:54:45 -0300 Subject: [PATCH] OverwriteRelayInformation --- handlers.go | 8 +++++++- relay.go | 29 +++++++++++++++-------------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/handlers.go b/handlers.go index 9b117e8..d4150c3 100644 --- a/handlers.go +++ b/handlers.go @@ -256,5 +256,11 @@ func (rl *Relay) HandleWebsocket(w http.ResponseWriter, r *http.Request) { func (rl *Relay) HandleNIP11(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/nostr+json") - json.NewEncoder(w).Encode(rl.Info) + + info := *rl.Info + for _, ovw := range rl.OverwriteRelayInformation { + info = ovw(r.Context(), r, info) + } + + json.NewEncoder(w).Encode(info) } diff --git a/relay.go b/relay.go index eaf0a63..97f4ed1 100644 --- a/relay.go +++ b/relay.go @@ -42,20 +42,21 @@ func NewRelay() *Relay { type Relay struct { ServiceURL string // required for nip-42 - RejectEvent []func(ctx context.Context, event *nostr.Event) (reject bool, msg string) - RejectFilter []func(ctx context.Context, filter nostr.Filter) (reject bool, msg string) - RejectCountFilter []func(ctx context.Context, filter nostr.Filter) (reject bool, msg string) - OverwriteDeletionOutcome []func(ctx context.Context, target *nostr.Event, deletion *nostr.Event) (acceptDeletion bool, msg string) - OverwriteResponseEvent []func(ctx context.Context, event *nostr.Event) - OverwriteFilter []func(ctx context.Context, filter *nostr.Filter) - OverwriteCountFilter []func(ctx context.Context, filter *nostr.Filter) - StoreEvent []func(ctx context.Context, event *nostr.Event) error - DeleteEvent []func(ctx context.Context, event *nostr.Event) error - QueryEvents []func(ctx context.Context, filter nostr.Filter) (chan *nostr.Event, error) - CountEvents []func(ctx context.Context, filter nostr.Filter) (int64, error) - OnAuth []func(ctx context.Context, pubkey string) - OnConnect []func(ctx context.Context) - OnEventSaved []func(ctx context.Context, event *nostr.Event) + RejectEvent []func(ctx context.Context, event *nostr.Event) (reject bool, msg string) + RejectFilter []func(ctx context.Context, filter nostr.Filter) (reject bool, msg string) + RejectCountFilter []func(ctx context.Context, filter nostr.Filter) (reject bool, msg string) + OverwriteDeletionOutcome []func(ctx context.Context, target *nostr.Event, deletion *nostr.Event) (acceptDeletion bool, msg string) + OverwriteResponseEvent []func(ctx context.Context, event *nostr.Event) + OverwriteFilter []func(ctx context.Context, filter *nostr.Filter) + OverwriteCountFilter []func(ctx context.Context, filter *nostr.Filter) + OverwriteRelayInformation []func(ctx context.Context, r *http.Request, info nip11.RelayInformationDocument) nip11.RelayInformationDocument + StoreEvent []func(ctx context.Context, event *nostr.Event) error + DeleteEvent []func(ctx context.Context, event *nostr.Event) error + QueryEvents []func(ctx context.Context, filter nostr.Filter) (chan *nostr.Event, error) + CountEvents []func(ctx context.Context, filter nostr.Filter) (int64, error) + OnAuth []func(ctx context.Context, pubkey string) + OnConnect []func(ctx context.Context) + OnEventSaved []func(ctx context.Context, event *nostr.Event) // editing info will affect Info *nip11.RelayInformationDocument