Revert prettyJsonOrRaw update and use go-nostr v1.8.4 for all user's metadata

This commit is contained in:
Daniele Tonon
2023-05-25 13:58:30 +02:00
parent 3a7e3d02ad
commit 0c90ec92ea
5 changed files with 31 additions and 20 deletions

View File

@@ -63,7 +63,7 @@
<div class="column columnA">
<div class="name">
{{.content_json.name}} <span class="display">{{.content_json.display_name}}</span>
{{.metadata.Name}} <span class="display">{{.metadata.DisplayName}}</span>
</div>
<div class="pic-wrapper">
<img class="pic" src="{{ .metadata.Picture }}" />
@@ -76,14 +76,14 @@
<div class="column columnB">
<div class="field name">
{{.content_json.name}} <span class="display">{{.content_json.display_name}}</span>
{{.metadata.Name}} <span class="display">{{.metadata.DisplayName}}</span>
</div>
<div class="field separator long"></div>
<div class="field">
<a href="{{.content_json.website}}">{{.content_json.website}}</a>
<a href="{{.metadata.Website}}">{{.metadata.Website}}</a>
</div>
<div class="field">
{{.content_json.about}}
{{.metadata.About}}
</div>
<div class="field separator"></div>
<div class="field">
@@ -92,11 +92,11 @@
</div>
<div class="field">
<div class="label">NIP-05</div>
{{.content_json.nip05}}
{{.metadata.NIP05}}
</div>
<div class="field">
<div class="label">LN Address</div>
{{.content_json.lud16}}
{{.metadata.LUD16}}
</div>
<div class="field">

5
go.mod
View File

@@ -7,7 +7,7 @@ require (
github.com/die-net/lrucache v0.0.0-20220628165024-20a71bc65bf1
github.com/lukevers/freetype-go v0.0.0-20150513150840-77e276735410
github.com/mailru/easyjson v0.7.7
github.com/nbd-wtf/go-nostr v0.18.1-0.20230509030905-52a493fd9666
github.com/nbd-wtf/go-nostr v0.18.4
github.com/pelletier/go-toml v1.9.5
golang.org/x/image v0.0.0-20190802002840-cff245a6509b
)
@@ -23,6 +23,9 @@ require (
github.com/gobwas/pool v0.2.1 // indirect
github.com/gobwas/ws v1.2.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/tidwall/gjson v1.14.4 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
golang.org/x/exp v0.0.0-20221106115401-f9659909a136 // indirect
golang.org/x/sys v0.6.0 // indirect
)

14
go.sum
View File

@@ -69,8 +69,12 @@ github.com/lukevers/freetype-go v0.0.0-20150513150840-77e276735410 h1:ED5jVfC//X
github.com/lukevers/freetype-go v0.0.0-20150513150840-77e276735410/go.mod h1:cnsFc3HOpydgckvXF3xq4fvlLFOAuTh4VyJ118x8LQc=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/nbd-wtf/go-nostr v0.18.1-0.20230509030905-52a493fd9666 h1:dWnwxgOl+dnVsKQLoNo5TaYJB7opG3LUIZ0YPl63iQI=
github.com/nbd-wtf/go-nostr v0.18.1-0.20230509030905-52a493fd9666/go.mod h1:fN8trCzHEtsf2954h8neqNERM/OXnCYI71nA4wWCobI=
github.com/nbd-wtf/go-nostr v0.18.4-0.20230514132335-123d3a6a9ab1 h1:rfkAcjBBR7j9aHRYIn+VjCO12lt8Bero5/cYPmO6Q6Q=
github.com/nbd-wtf/go-nostr v0.18.4-0.20230514132335-123d3a6a9ab1/go.mod h1:GPJOOK8US38kz+bfb9nWe873Xu0e6bXlThejOs1LTkc=
github.com/nbd-wtf/go-nostr v0.18.4-0.20230525112312-5c0f8bff83ea h1:L4eHtPd5bgj7Cl9j+TA5fZaQGVPt8SunZhqNtMbqzWo=
github.com/nbd-wtf/go-nostr v0.18.4-0.20230525112312-5c0f8bff83ea/go.mod h1:GPJOOK8US38kz+bfb9nWe873Xu0e6bXlThejOs1LTkc=
github.com/nbd-wtf/go-nostr v0.18.4 h1:P5qHEvvwS6DMaDMD82fP66M3kFBJnNQATczGH93rC0s=
github.com/nbd-wtf/go-nostr v0.18.4/go.mod h1:GPJOOK8US38kz+bfb9nWe873Xu0e6bXlThejOs1LTkc=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
@@ -92,6 +96,12 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.5 h1:s5PTfem8p8EbKQOctVV53k6jCJt3UX4IEJzwh+C324Q=
github.com/stretchr/testify v1.7.5/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc=
github.com/tidwall/gjson v1.14.4 h1:uo0p8EbA09J7RQaflQ1aBRffTR7xedD2bcIVSYxLnkM=
github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=

View File

@@ -143,17 +143,16 @@ func render(w http.ResponseWriter, r *http.Request) {
// : ''
textImageURL := ""
content := ""
content_json := make(map[string]interface{})
description := ""
if useTextImage {
textImageURL = fmt.Sprintf("https://%s/image/%s", hostname, code)
if subject != "" {
content = fmt.Sprintf("%s -- %s", subject, seenOnRelays)
description = fmt.Sprintf("%s -- %s", subject, seenOnRelays)
} else {
content = seenOnRelays
description = seenOnRelays
}
} else {
content_json, content = prettyJsonOrRaw(event.Content)
description = prettyJsonOrRaw(event.Content)
}
eventJSON, _ := json.MarshalIndent(event, "", " ")
@@ -169,8 +168,7 @@ func render(w http.ResponseWriter, r *http.Request) {
"naddr": naddr,
"metadata": metadata,
"authorLong": authorLong,
"content": content,
"content_json": content_json,
"description": description,
"textImageURL": textImageURL,
"videoType": videoType,
"image": image,

View File

@@ -81,14 +81,14 @@ func mergeMaps[K comparable, V any](m1 map[K]V, m2 map[K]V) map[K]V {
return m1
}
func prettyJsonOrRaw(j string) (map[string]interface{}, string) {
var parsedContent map[string]interface{}
func prettyJsonOrRaw(j string) string {
var parsedContent any
if err := json.Unmarshal([]byte(j), &parsedContent); err == nil {
if t, err := toml.Marshal(parsedContent); err == nil && len(t) > 0 {
return parsedContent, string(t)
return string(t)
}
}
return nil, j
return j
}
func getPreviewStyle(r *http.Request) string {