forked from fiatjaf/njump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
render_homepage.go
48 lines (41 loc) · 1.1 KB
/
render_homepage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"context"
"net/http"
"time"
"github.com/nbd-wtf/go-nostr"
"github.com/nbd-wtf/go-nostr/nip19"
)
func renderHomepage(w http.ResponseWriter, r *http.Request) {
typ := "homepage"
w.Header().Set("Cache-Control", "max-age=3600")
npubsHex := cache.GetPaginatedkeys("pa", 1, 50)
npubs := []string{}
for i := 0; i < len(npubsHex); i++ {
npub, _ := nip19.EncodePublicKey(npubsHex[i])
npubs = append(npubs, npub)
}
ctx, cancel := context.WithTimeout(r.Context(), time.Second*5)
defer cancel()
var lastEvents []*nostr.Event
if relay, err := pool.EnsureRelay("nostr.wine"); err == nil {
lastEvents, _ = relay.QuerySync(ctx, nostr.Filter{
Kinds: []int{1},
Limit: 50,
})
}
lastNotes := []string{}
relay := []string{"wss://nostr.wine"}
for _, n := range lastEvents {
nevent, _ := nip19.EncodeEvent(n.ID, relay, n.PubKey)
lastNotes = append(lastNotes, nevent)
}
params := map[string]any{
"npubs": npubs,
"lastNotes": lastNotes,
}
if err := tmpl.ExecuteTemplate(w, templateMapping[typ], params); err != nil {
log.Error().Err(err).Msg("error rendering")
return
}
}