Store json the lazy way...
This commit is contained in:
parent
4747b15d62
commit
5c35f2daac
1 changed files with 11 additions and 5 deletions
|
@ -2,6 +2,7 @@ package nostr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
b64 "encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -12,7 +13,6 @@ import (
|
||||||
"git.minhas.io/asara/well-goknown/lnd"
|
"git.minhas.io/asara/well-goknown/lnd"
|
||||||
"git.minhas.io/asara/well-goknown/logger"
|
"git.minhas.io/asara/well-goknown/logger"
|
||||||
"git.minhas.io/asara/well-goknown/redis"
|
"git.minhas.io/asara/well-goknown/redis"
|
||||||
"github.com/davecgh/go-spew/spew"
|
|
||||||
"github.com/nbd-wtf/go-nostr/nip19"
|
"github.com/nbd-wtf/go-nostr/nip19"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -72,6 +72,7 @@ func RequestNostrAddr(w http.ResponseWriter, r *http.Request) {
|
||||||
user = nostrWellKnown{Names: names}
|
user = nostrWellKnown{Names: names}
|
||||||
}
|
}
|
||||||
jsonUser, _ := json.Marshal(user)
|
jsonUser, _ := json.Marshal(user)
|
||||||
|
enc := b64.StdEncoding.EncodeToString([]byte(jsonUser))
|
||||||
|
|
||||||
// generate the payment request
|
// generate the payment request
|
||||||
exp := time.Until(time.Now().Add(time.Minute * 15))
|
exp := time.Until(time.Now().Add(time.Minute * 15))
|
||||||
|
@ -81,11 +82,10 @@ func RequestNostrAddr(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
requestKey := getRkey("requested", r.FormValue("Name"), getHostname(r.Host))
|
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 {
|
if err != nil {
|
||||||
l.Error().Msg("unable to connect to redis")
|
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)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
dec, err := b64.StdEncoding.DecodeString(addr)
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
json.NewEncoder(w).Encode(addr)
|
w.Write(dec)
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddNostrAddr(n NostrRequest) {
|
func AddNostrAddr(n NostrRequest) {
|
||||||
|
@ -142,7 +147,8 @@ func AddNostrAddr(n NostrRequest) {
|
||||||
l.Error().Msg("unable to connect to redis")
|
l.Error().Msg("unable to connect to redis")
|
||||||
}
|
}
|
||||||
nameKey := getRkey("verified", n.Name, n.Hostname)
|
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 {
|
if err != nil {
|
||||||
l.Error().Msg("unable to connect to redis")
|
l.Error().Msg("unable to connect to redis")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue