-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathnip11.go
38 lines (31 loc) · 1020 Bytes
/
nip11.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
package khatru
import (
"encoding/json"
"net/http"
"strings"
)
func (rl *Relay) HandleNIP11(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/nostr+json")
info := *rl.Info
if len(rl.DeleteEvent) > 0 {
info.AddSupportedNIP(9)
}
if len(rl.CountEvents) > 0 {
info.AddSupportedNIP(45)
}
if rl.Negentropy {
info.AddSupportedNIP(77)
}
// resolve relative icon and banner URLs against base URL
baseURL := rl.getBaseURL(r)
if info.Icon != "" && !strings.HasPrefix(info.Icon, "http://") && !strings.HasPrefix(info.Icon, "https://") {
info.Icon = strings.TrimSuffix(baseURL, "/") + "/" + strings.TrimPrefix(info.Icon, "/")
}
if info.Banner != "" && !strings.HasPrefix(info.Banner, "http://") && !strings.HasPrefix(info.Banner, "https://") {
info.Banner = strings.TrimSuffix(baseURL, "/") + "/" + strings.TrimPrefix(info.Banner, "/")
}
for _, ovw := range rl.OverwriteRelayInformation {
info = ovw(r.Context(), r, info)
}
json.NewEncoder(w).Encode(info)
}