also implement listallowedpubkeys.

This commit is contained in:
fiatjaf 2024-07-11 16:00:45 -03:00
parent 0c3b4c7217
commit 7f82779f62
2 changed files with 12 additions and 0 deletions

View File

@ -92,6 +92,7 @@ func main() {
relay.ManagementAPI.AllowPubKey = allowPubKeyHandler
relay.ManagementAPI.BanPubKey = banPubKeyHandler
relay.ManagementAPI.ListAllowedPubKeys = listAllowedPubKeysHandler
// load users registry
if err := loadWhitelist(); err != nil {

View File

@ -5,6 +5,7 @@ import (
"fmt"
"github.com/fiatjaf/khatru"
"github.com/nbd-wtf/go-nostr/nip86"
)
func allowPubKeyHandler(ctx context.Context, pubkey, reason string) error {
@ -36,3 +37,13 @@ func banPubKeyHandler(ctx context.Context, pubkey, reason string) error {
return saveWhitelist()
}
func listAllowedPubKeysHandler(ctx context.Context) ([]nip86.PubKeyReason, error) {
list := make([]nip86.PubKeyReason, len(whitelist))
i := 0
for pubkey, inviter := range whitelist {
list[i] = nip86.PubKeyReason{PubKey: pubkey, Reason: fmt.Sprintf("invited by %s", inviter)}
i++
}
return list, nil
}