Add npubs archive

Add more npubs
This commit is contained in:
Daniele Tonon
2023-07-18 01:34:33 +02:00
parent 4e587cf186
commit eabec9b590
6 changed files with 231 additions and 1 deletions

View File

@@ -1,11 +1,13 @@
package main
import (
"context"
"encoding/json"
"fmt"
"net/http"
"regexp"
"strings"
"time"
"github.com/gomarkdown/markdown"
"github.com/gomarkdown/markdown/html"
@@ -344,3 +346,22 @@ func trimProtocol(relay string) string {
relay = strings.TrimPrefix(relay, "ws:/") // Some browsers replace upfront '//' with '/'
return relay
}
func loadNpubsArchive(ctx context.Context) {
fmt.Println("Refreshing the npubs archive")
contactsArchive := make([]string, 0, 500)
for _, pubkey := range trustedPubKeys {
ctx, cancel := context.WithTimeout(ctx, time.Second*4)
pubkeyContacts := contactsForPubkey(ctx, pubkey)
contactsArchive = append(contactsArchive, pubkeyContacts...)
cancel()
}
contactsArchive = unique(contactsArchive)
for _, contact := range contactsArchive {
fmt.Printf("Adding contact %s\n", contact)
cache.SetWithTTL("pa:"+contact, nil, time.Hour*24*90)
}
}