diff --git a/db.go b/db.go index a064687..8992880 100644 --- a/db.go +++ b/db.go @@ -31,6 +31,11 @@ type Params struct { NotifyZaps bool `json:"notifyzaps"` NotifyZapComment bool `json:"notifycomments"` NotifyNonZap bool `json:"notifynonzaps"` + Image struct { + DataURI string + Bytes []byte + Ext string + } } func SaveName( @@ -44,6 +49,17 @@ func SaveName( name = strings.ToLower(name) domain = strings.ToLower(domain) + if params.Npub != "" && s.GetNostrProfile { + NostrProfile, err := GetNostrProfileMetaData(params.Npub) + if err == nil { + err = addImageToProfile(params, NostrProfile.Picture) + if err != nil { + + } + } + + } + key := []byte(getID(name, domain)) pin = ComputePIN(name, domain) diff --git a/invoice.go b/invoice.go index 0d1043f..a87c6f0 100644 --- a/invoice.go +++ b/invoice.go @@ -29,25 +29,26 @@ func metaData(params *Params) lnurl.Metadata { LightningAddress: fmt.Sprintf("%s@%s", params.Name, params.Domain), } - /* if params.Npub != "" && s.GetNostrProfile { - NostrProfile, err := GetNostrProfileMetaData(params.Npub) - if err == nil { - addImageToMetaData(&metadata, NostrProfile.Picture) + if params.Npub != "" && s.GetNostrProfile { + if params.Image.DataURI != "" { + metadata.Image.Bytes = params.Image.Bytes + metadata.Image.Ext = params.Image.Ext + metadata.Image.DataURI = params.Image.DataURI } - } */ + } return metadata } // addImageToMetaData adds an image to the LNURL metadata -func addImageToMetaData(metadata *lnurl.Metadata, imageurl string) { +func addImageToProfile(params *Params, imageurl string) (err error) { // Download and resize profile picture picture, err := DownloadProfilePicture(imageurl) if err != nil { log.Debug().Str("Downloading profile picture", err.Error()).Msg("Error") - return + return err } // Determine image format @@ -59,13 +60,15 @@ func addImageToMetaData(metadata *lnurl.Metadata, imageurl string) { ext = "png" } else { log.Debug().Str("Detecting image format", "unknown format").Msg("Error") - return + return fmt.Errorf("Detecting image format: unknown format") } // Set image metadata in LNURL metadata - metadata.Image.Ext = ext - metadata.Image.DataURI = "data:" + contentType + ";base64," + base64.StdEncoding.EncodeToString(picture) - metadata.Image.Bytes = picture + params.Image.Ext = ext + params.Image.DataURI = "data:" + contentType + ";base64," + base64.StdEncoding.EncodeToString(picture) + params.Image.Bytes = picture + + return nil } func DownloadProfilePicture(url string) ([]byte, error) { diff --git a/nostr.go b/nostr.go index 8c25292..8ebf632 100644 --- a/nostr.go +++ b/nostr.go @@ -150,10 +150,13 @@ func GetNostrProfileMetaData(npub string) (nostr.ProfileMetadata, error) { ctx, _ := context.WithTimeout(context.Background(), 3*time.Second) var metadata *nostr.ProfileMetadata - // connect to any relay - url := "wss://relay.damus.io" + // connect to first relay, todo, check on all/for errors + rel := Relays[0] + log.Printf("Get Image from: %s . If you receive an error use another relay on first position in RELAYS option", rel) + url := rel relay, err := nostr.RelayConnect(ctx, url) if err != nil { + log.Printf("Could not get Image") return *metadata, err } @@ -191,6 +194,7 @@ func GetNostrProfileMetaData(npub string) (nostr.ProfileMetadata, error) { } else { err = fmt.Errorf("no profile found for npub %s on relay %s", npub, url) } + log.Printf("Success getting Nostr Profile") return *metadata, err }