mirror of
https://github.com/aljazceru/njump.git
synced 2025-12-18 23:04:21 +01:00
hardcode relays for the sitemap, just a few "safe" relays.
This commit is contained in:
@@ -10,11 +10,6 @@ import (
|
|||||||
"github.com/nbd-wtf/go-nostr/nip19"
|
"github.com/nbd-wtf/go-nostr/nip19"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
NPUBS_ARCHIVE = iota
|
|
||||||
RELAYS_ARCHIVE = iota
|
|
||||||
)
|
|
||||||
|
|
||||||
func renderArchive(w http.ResponseWriter, r *http.Request) {
|
func renderArchive(w http.ResponseWriter, r *http.Request) {
|
||||||
lastIndex := strings.LastIndex(r.URL.Path, "/")
|
lastIndex := strings.LastIndex(r.URL.Path, "/")
|
||||||
page := 1
|
page := 1
|
||||||
@@ -28,28 +23,21 @@ func renderArchive(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
prefix := ""
|
var data []string
|
||||||
pathPrefix := ""
|
pathPrefix := ""
|
||||||
var area int
|
|
||||||
if strings.HasPrefix(r.URL.Path[1:], "npubs-archive") {
|
if strings.HasPrefix(r.URL.Path[1:], "npubs-archive") {
|
||||||
area = NPUBS_ARCHIVE
|
|
||||||
prefix = "pa:"
|
|
||||||
pathPrefix = ""
|
pathPrefix = ""
|
||||||
} else if strings.HasPrefix(r.URL.Path[1:], "relays-archive") {
|
data = make([]string, 0, 5000)
|
||||||
area = RELAYS_ARCHIVE
|
keys := cache.GetPaginatedKeys("pa:", page, 5000)
|
||||||
prefix = "ra:"
|
for _, key := range keys {
|
||||||
pathPrefix = "r/"
|
|
||||||
}
|
|
||||||
|
|
||||||
keys := cache.GetPaginatedKeys(prefix, page, 5000)
|
|
||||||
data := []string{}
|
|
||||||
for _, key := range keys {
|
|
||||||
switch area {
|
|
||||||
case NPUBS_ARCHIVE:
|
|
||||||
npub, _ := nip19.EncodePublicKey(key[3:])
|
npub, _ := nip19.EncodePublicKey(key[3:])
|
||||||
data = append(data, npub)
|
data = append(data, npub)
|
||||||
case RELAYS_ARCHIVE:
|
}
|
||||||
data = append(data, trimProtocol(key[3:]))
|
} else if strings.HasPrefix(r.URL.Path[1:], "relays-archive") {
|
||||||
|
data = []string{
|
||||||
|
"pyramid.fiatjaf.com",
|
||||||
|
"nostr.wine",
|
||||||
|
"140.f7z.io",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +56,6 @@ func renderArchive(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Add("content-type", "text/xml")
|
w.Header().Add("content-type", "text/xml")
|
||||||
w.Header().Set("Cache-Control", "public, max-age=3600")
|
|
||||||
w.Write([]byte(XML_HEADER))
|
w.Write([]byte(XML_HEADER))
|
||||||
SitemapTemplate.Render(w, &SitemapPage{
|
SitemapTemplate.Render(w, &SitemapPage{
|
||||||
Host: s.Domain,
|
Host: s.Domain,
|
||||||
|
|||||||
28
routines.go
28
routines.go
@@ -18,7 +18,6 @@ func updateArchives(ctx context.Context) {
|
|||||||
|
|
||||||
for {
|
for {
|
||||||
loadNpubsArchive(ctx)
|
loadNpubsArchive(ctx)
|
||||||
loadRelaysArchive(ctx)
|
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
@@ -83,30 +82,3 @@ func loadNpubsArchive(ctx context.Context) {
|
|||||||
cache.SetWithTTL("pa:"+contact, nil, time.Hour*24*90)
|
cache.SetWithTTL("pa:"+contact, nil, time.Hour*24*90)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadRelaysArchive(ctx context.Context) {
|
|
||||||
log.Debug().Msg("refreshing the relays archive")
|
|
||||||
|
|
||||||
relaysArchive := make([]string, 0, 500)
|
|
||||||
|
|
||||||
for _, pubkey := range s.TrustedPubKeys {
|
|
||||||
ctx, cancel := context.WithTimeout(ctx, time.Second*4)
|
|
||||||
pubkeyContacts := relaysForPubkey(ctx, pubkey, relayConfig.Profiles...)
|
|
||||||
relaysArchive = append(relaysArchive, pubkeyContacts...)
|
|
||||||
cancel()
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, relay := range unique(relaysArchive) {
|
|
||||||
for _, excluded := range relayConfig.ExcludedRelays {
|
|
||||||
if strings.Contains(relay, excluded) {
|
|
||||||
log.Debug().Msgf("skipping relay %s", relay)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if strings.Contains(relay, "/npub1") {
|
|
||||||
continue // skip relays with personalyzed query like filter.nostr.wine
|
|
||||||
}
|
|
||||||
log.Debug().Msgf("adding relay %s", relay)
|
|
||||||
cache.SetWithTTL("ra:"+relay, nil, time.Hour*24*7)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user