From 5c35f2daac3a400c71e26faec2bd0be4451cd417 Mon Sep 17 00:00:00 2001 From: Asara Date: Sat, 29 Apr 2023 15:25:28 -0400 Subject: [PATCH] Store json the lazy way... --- nostr/nostr.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/nostr/nostr.go b/nostr/nostr.go index 8db929a..454f058 100644 --- a/nostr/nostr.go +++ b/nostr/nostr.go @@ -2,6 +2,7 @@ package nostr import ( "context" + b64 "encoding/base64" "encoding/json" "errors" "fmt" @@ -12,7 +13,6 @@ import ( "git.minhas.io/asara/well-goknown/lnd" "git.minhas.io/asara/well-goknown/logger" "git.minhas.io/asara/well-goknown/redis" - "github.com/davecgh/go-spew/spew" "github.com/nbd-wtf/go-nostr/nip19" ) @@ -72,6 +72,7 @@ func RequestNostrAddr(w http.ResponseWriter, r *http.Request) { user = nostrWellKnown{Names: names} } jsonUser, _ := json.Marshal(user) + enc := b64.StdEncoding.EncodeToString([]byte(jsonUser)) // generate the payment request exp := time.Until(time.Now().Add(time.Minute * 15)) @@ -81,11 +82,10 @@ func RequestNostrAddr(w http.ResponseWriter, r *http.Request) { return } requestKey := getRkey("requested", r.FormValue("Name"), getHostname(r.Host)) - err = redisCli.Client.Set(ctx, requestKey, jsonUser, exp).Err() + err = redisCli.Client.Set(ctx, requestKey, enc, exp).Err() if err != nil { l.Error().Msg("unable to connect to redis") } - spew.Dump(paymentReq) } } @@ -111,10 +111,15 @@ func GetNostrAddr(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusNotFound) return } + dec, err := b64.StdEncoding.DecodeString(addr) + if err != nil { + w.WriteHeader(http.StatusInternalServerError) + return + } w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) - json.NewEncoder(w).Encode(addr) + w.Write(dec) } func AddNostrAddr(n NostrRequest) { @@ -142,7 +147,8 @@ func AddNostrAddr(n NostrRequest) { l.Error().Msg("unable to connect to redis") } nameKey := getRkey("verified", n.Name, n.Hostname) - err = redisCli.Client.Set(ctx, nameKey, jsonUser, 0).Err() + enc := b64.StdEncoding.EncodeToString([]byte(jsonUser)) + err = redisCli.Client.Set(ctx, nameKey, enc, 0).Err() if err != nil { l.Error().Msg("unable to connect to redis") }