mirror of
https://github.com/aljazceru/njump.git
synced 2025-12-18 14:54:24 +01:00
update nostr-sdk to fix relay lists and move things around.
This commit is contained in:
37
data.go
37
data.go
@@ -27,7 +27,7 @@ type Data struct {
|
|||||||
modifiedAt string
|
modifiedAt string
|
||||||
parentLink template.HTML
|
parentLink template.HTML
|
||||||
metadata Metadata
|
metadata Metadata
|
||||||
authorRelays []string
|
authorRelaysPretty []string
|
||||||
authorLong string
|
authorLong string
|
||||||
renderableLastNotes []EnhancedEvent
|
renderableLastNotes []EnhancedEvent
|
||||||
kindDescription string
|
kindDescription string
|
||||||
@@ -70,6 +70,20 @@ func grabData(ctx context.Context, code string, isProfileSitemap bool) (*Data, e
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data.authorRelaysPretty = make([]string, 0, len(relays))
|
||||||
|
for _, url := range relaysForPubkey(ctx, event.PubKey) {
|
||||||
|
if isntRealRelay(url) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, excluded := range relayConfig.ExcludedRelays {
|
||||||
|
if strings.Contains(url, excluded) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data.authorRelaysPretty = append(data.authorRelaysPretty, trimProtocol(url))
|
||||||
|
}
|
||||||
|
data.authorRelaysPretty = unique(data.authorRelaysPretty)
|
||||||
|
|
||||||
npub, _ := nip19.EncodePublicKey(event.PubKey)
|
npub, _ := nip19.EncodePublicKey(event.PubKey)
|
||||||
npubShort := npub[:8] + "…" + npub[len(npub)-4:]
|
npubShort := npub[:8] + "…" + npub[len(npub)-4:]
|
||||||
data.authorLong = npub // hopefully will be replaced later
|
data.authorLong = npub // hopefully will be replaced later
|
||||||
@@ -79,7 +93,6 @@ func grabData(ctx context.Context, code string, isProfileSitemap bool) (*Data, e
|
|||||||
data.naddrNaked = ""
|
data.naddrNaked = ""
|
||||||
data.createdAt = time.Unix(int64(event.CreatedAt), 0).Format("2006-01-02 15:04:05")
|
data.createdAt = time.Unix(int64(event.CreatedAt), 0).Format("2006-01-02 15:04:05")
|
||||||
data.modifiedAt = time.Unix(int64(event.CreatedAt), 0).Format("2006-01-02T15:04:05Z07:00")
|
data.modifiedAt = time.Unix(int64(event.CreatedAt), 0).Format("2006-01-02T15:04:05Z07:00")
|
||||||
data.authorRelays = []string{}
|
|
||||||
|
|
||||||
if event.Kind >= 30000 && event.Kind < 40000 {
|
if event.Kind >= 30000 && event.Kind < 40000 {
|
||||||
if d := event.Tags.GetFirst([]string{"d", ""}); d != nil {
|
if d := event.Tags.GetFirst([]string{"d", ""}); d != nil {
|
||||||
@@ -93,25 +106,7 @@ func grabData(ctx context.Context, code string, isProfileSitemap bool) (*Data, e
|
|||||||
switch event.Kind {
|
switch event.Kind {
|
||||||
case 0:
|
case 0:
|
||||||
data.templateId = Profile
|
data.templateId = Profile
|
||||||
{
|
lastNotes := authorLastNotes(ctx, event.PubKey, isProfileSitemap)
|
||||||
rawAuthorRelays := []string{}
|
|
||||||
ctx, cancel := context.WithTimeout(ctx, time.Second*4)
|
|
||||||
rawAuthorRelays = relaysForPubkey(ctx, event.PubKey)
|
|
||||||
cancel()
|
|
||||||
for _, relay := range rawAuthorRelays {
|
|
||||||
for _, excluded := range relayConfig.ExcludedRelays {
|
|
||||||
if strings.Contains(relay, excluded) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if strings.Contains(relay, "/npub1") {
|
|
||||||
continue // skip relays with personalyzed query like filter.nostr.wine
|
|
||||||
}
|
|
||||||
data.authorRelays = append(data.authorRelays, trimProtocol(relay))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lastNotes := authorLastNotes(ctx, event.PubKey, data.authorRelays, isProfileSitemap)
|
|
||||||
data.renderableLastNotes = make([]EnhancedEvent, len(lastNotes))
|
data.renderableLastNotes = make([]EnhancedEvent, len(lastNotes))
|
||||||
for i, levt := range lastNotes {
|
for i, levt := range lastNotes {
|
||||||
data.renderableLastNotes[i] = EnhancedEvent{levt, []string{}}
|
data.renderableLastNotes[i] = EnhancedEvent{levt, []string{}}
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -17,7 +17,7 @@ require (
|
|||||||
github.com/microcosm-cc/bluemonday v1.0.24
|
github.com/microcosm-cc/bluemonday v1.0.24
|
||||||
github.com/nbd-wtf/emoji v0.0.3
|
github.com/nbd-wtf/emoji v0.0.3
|
||||||
github.com/nbd-wtf/go-nostr v0.30.2
|
github.com/nbd-wtf/go-nostr v0.30.2
|
||||||
github.com/nbd-wtf/nostr-sdk v0.2.0
|
github.com/nbd-wtf/nostr-sdk v0.2.1
|
||||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
|
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
|
||||||
github.com/pelletier/go-toml v1.9.5
|
github.com/pelletier/go-toml v1.9.5
|
||||||
github.com/pemistahl/lingua-go v1.4.0
|
github.com/pemistahl/lingua-go v1.4.0
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -167,8 +167,8 @@ github.com/nbd-wtf/emoji v0.0.3 h1:YtkT7MVPXvqU1SQjvC/CShlWexnREzqNCxmhUnL00CA=
|
|||||||
github.com/nbd-wtf/emoji v0.0.3/go.mod h1:tS6D9iI34qwBmWc5g8X7tVDkWXulqbTJRsvsM6QsS88=
|
github.com/nbd-wtf/emoji v0.0.3/go.mod h1:tS6D9iI34qwBmWc5g8X7tVDkWXulqbTJRsvsM6QsS88=
|
||||||
github.com/nbd-wtf/go-nostr v0.30.2 h1:dG/2X52/XDg+7phZH+BClcvA5D+S6dXvxJKkBaySEzI=
|
github.com/nbd-wtf/go-nostr v0.30.2 h1:dG/2X52/XDg+7phZH+BClcvA5D+S6dXvxJKkBaySEzI=
|
||||||
github.com/nbd-wtf/go-nostr v0.30.2/go.mod h1:tiKJY6fWYSujbTQb201Y+IQ3l4szqYVt+fsTnsm7FCk=
|
github.com/nbd-wtf/go-nostr v0.30.2/go.mod h1:tiKJY6fWYSujbTQb201Y+IQ3l4szqYVt+fsTnsm7FCk=
|
||||||
github.com/nbd-wtf/nostr-sdk v0.2.0 h1:IYg5xuPLt0zmL7GiHWeixDO2f47NYaIwb0MmoJRnHWw=
|
github.com/nbd-wtf/nostr-sdk v0.2.1 h1:Ae1186pm//Byy5gOIsB3Nhy6EQfTzOHeU9enRWVd204=
|
||||||
github.com/nbd-wtf/nostr-sdk v0.2.0/go.mod h1:iYZYgu0lilem16G8fk08FipgMOzsQs2bO1j6uEnRhvA=
|
github.com/nbd-wtf/nostr-sdk v0.2.1/go.mod h1:iYZYgu0lilem16G8fk08FipgMOzsQs2bO1j6uEnRhvA=
|
||||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
|
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
|
||||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
||||||
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
||||||
|
|||||||
8
nostr.go
8
nostr.go
@@ -216,7 +216,7 @@ func getEvent(ctx context.Context, code string, relayHints []string) (*nostr.Eve
|
|||||||
return result, allRelays, nil
|
return result, allRelays, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func authorLastNotes(ctx context.Context, pubkey string, relays []string, isSitemap bool) []*nostr.Event {
|
func authorLastNotes(ctx context.Context, pubkey string, isSitemap bool) []*nostr.Event {
|
||||||
limit := 100
|
limit := 100
|
||||||
store := true
|
store := true
|
||||||
useLocalStore := true
|
useLocalStore := true
|
||||||
@@ -242,7 +242,11 @@ func authorLastNotes(ctx context.Context, pubkey string, relays []string, isSite
|
|||||||
lastNotes = make([]*nostr.Event, 0, filter.Limit)
|
lastNotes = make([]*nostr.Event, 0, filter.Limit)
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
relays = unique(append(relays, getRandomRelay(), getRandomRelay()))
|
|
||||||
|
relays := limitAt(relaysForPubkey(ctx, pubkey), 5)
|
||||||
|
for len(relays) < 4 {
|
||||||
|
relays = unique(append(relays, getRandomRelay()))
|
||||||
|
}
|
||||||
ch := pool.SubManyEose(ctx, relays, nostr.Filters{filter})
|
ch := pool.SubManyEose(ctx, relays, nostr.Filters{filter})
|
||||||
out:
|
out:
|
||||||
for {
|
for {
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ func renderEmbedded(w http.ResponseWriter, r *http.Request, code string) {
|
|||||||
Metadata: data.metadata,
|
Metadata: data.metadata,
|
||||||
NormalizedAuthorWebsiteURL: normalizeWebsiteURL(data.metadata.Website),
|
NormalizedAuthorWebsiteURL: normalizeWebsiteURL(data.metadata.Website),
|
||||||
RenderedAuthorAboutText: template.HTML(basicFormatting(html.EscapeString(data.metadata.About), false, false, true)),
|
RenderedAuthorAboutText: template.HTML(basicFormatting(html.EscapeString(data.metadata.About), false, false, true)),
|
||||||
AuthorRelays: data.authorRelays,
|
AuthorRelays: data.authorRelaysPretty,
|
||||||
})
|
})
|
||||||
default:
|
default:
|
||||||
log.Error().Int("templateId", int(data.templateId)).Msg("no way to render")
|
log.Error().Int("templateId", int(data.templateId)).Msg("no way to render")
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ func renderProfile(w http.ResponseWriter, r *http.Request, code string) {
|
|||||||
NormalizedAuthorWebsiteURL: normalizeWebsiteURL(data.metadata.Website),
|
NormalizedAuthorWebsiteURL: normalizeWebsiteURL(data.metadata.Website),
|
||||||
RenderedAuthorAboutText: template.HTML(basicFormatting(html.EscapeString(data.metadata.About), false, false, false)),
|
RenderedAuthorAboutText: template.HTML(basicFormatting(html.EscapeString(data.metadata.About), false, false, false)),
|
||||||
Nprofile: data.nprofile,
|
Nprofile: data.nprofile,
|
||||||
AuthorRelays: data.authorRelays,
|
AuthorRelays: data.authorRelaysPretty,
|
||||||
LastNotes: data.renderableLastNotes,
|
LastNotes: data.renderableLastNotes,
|
||||||
Clients: generateClientList(data.event.Kind, data.nprofile,
|
Clients: generateClientList(data.event.Kind, data.nprofile,
|
||||||
func(c ClientReference, s string) string {
|
func(c ClientReference, s string) string {
|
||||||
|
|||||||
Reference in New Issue
Block a user