From 24ec61a197eccf6870f159d639dd22968afdf8a6 Mon Sep 17 00:00:00 2001 From: Believethehype Date: Wed, 15 Mar 2023 18:57:49 +0100 Subject: [PATCH] made Profilepicture (experimental) optional --- README.md | 4 ++-- main.go | 10 +++++----- nostr.go | 9 ++++----- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 3276b68..882e257 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Federated Lightning Address Server (with NIP57 Zap support) > The Nostr private key in the parameters should be in bench32 format (`nsec..`) and it should be a new one. It is needed to sign messages only, so does not need to be your main account key. -(`GetNostrProfile`) is still experimental and should be left on false in case it causes errors. The idea is to provide the Nostr Profile picture to wallets that support it. +(`GET_NOSTR_PROFILE`) is still experimental and should be left on false in case it causes errors. The idea is to provide the Nostr Profile picture to wallets that support it. ``` PORT=17422 @@ -23,7 +23,7 @@ SITE_NAME=Bitmia NOSTR_PRIVATE_KEY=nsec213.... FORWARD_URL=https://thepageyouwanttoshowasmainpage.com NIP05=true -GetNostrProfile=false +GET_NOSTR_PROFILE=false ``` 3. Start the app with `./satdress` or `nohup ./satdress &` for a background task diff --git a/main.go b/main.go index eaae084..44f5ae0 100644 --- a/main.go +++ b/main.go @@ -24,16 +24,16 @@ type Settings struct { Domain string `envconfig:"DOMAIN" required:"true"` // GlobalUsers means that user@ part is globally unique across all domains // WARNING: if you toggle this existing users won't work anymore for safety reasons! - GlobalUsers bool `envconfig:"GLOBAL_USERS" required:"false" default:false` + GlobalUsers bool `envconfig:"GLOBAL_USERS" default:"false"` Secret string `envconfig:"SECRET" required:"true"` SiteOwnerName string `envconfig:"SITE_OWNER_NAME" required:"true"` SiteOwnerURL string `envconfig:"SITE_OWNER_URL" required:"true"` SiteName string `envconfig:"SITE_NAME" required:"true"` NostrPrivateKey string `envconfig:"NOSTR_PRIVATE_KEY" required:"false" default:""` - ForwardMainPageUrl string `envconfig:"FORWARD_URL"` - Nip05 bool `envconfig:"NIP05" required:"false" default:false` - GetNostrProfile bool `envconfig:"GetNostrProfile" required:"false" default:false` - ForceMigrate bool `envconfig:"FORCE_MIGRATE" required:"false" default:false` + ForwardMainPageUrl string `envconfig:"FORWARD_URL" required:"false"` + Nip05 bool `envconfig:"NIP05" default:"false" required:"false"` + GetNostrProfile bool `envconfig:"GET_NOSTR_PROFILE" required:"false" default:"false"` + ForceMigrate bool `envconfig:"FORCE_MIGRATE" default:"false"` TorProxyURL string `envconfig:"TOR_PROXY_URL"` } diff --git a/nostr.go b/nostr.go index 29d6c95..c7f0eda 100644 --- a/nostr.go +++ b/nostr.go @@ -82,14 +82,13 @@ func handleNip05(w http.ResponseWriter, r *http.Request) { } func GetNostrProfileMetaData(npub string) (nostr.ProfileMetadata, error) { - ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) + ctx, _ := context.WithTimeout(context.Background(), 3*time.Second) var metadata *nostr.ProfileMetadata // connect to any relay url := "wss://relay.damus.io" relay, err := nostr.RelayConnect(ctx, url) if err != nil { - cancel() return *metadata, err } @@ -105,7 +104,6 @@ func GetNostrProfileMetaData(npub string) (nostr.ProfileMetadata, error) { Limit: 1, }} } else { - cancel() return *metadata, err } @@ -114,15 +112,16 @@ func GetNostrProfileMetaData(npub string) (nostr.ProfileMetadata, error) { go func() { <-sub.EndOfStoredEvents - cancel() + }() for ev := range sub.Events { evs = append(evs, *ev) } - metadata, err = nostr.ParseMetadata(evs[0]) + relay.Close() + metadata, err = nostr.ParseMetadata(evs[0]) return *metadata, err }