| 1 | package tinyclient |
| 2 | |
| 3 | import ( |
| 4 | "math/big" |
| 5 | "strings" |
| 6 | |
| 7 | "fiatjaf.com/nostr" |
| 8 | event "github.com/FelineStateMachine/tinyrelay/protocol/nostr" |
| 9 | ) |
| 10 | |
| 11 | const ( |
| 12 | kindSite = 15128 |
| 13 | kindNamedSite = 35128 |
| 14 | kindSiteSnapshot = 5128 |
| 15 | ) |
| 16 | |
| 17 | // siteLabel derives the NIP-5A host label for display, without linking the |
| 18 | // storage-backed site server into the frontend. The relay validates manifests. |
| 19 | func siteLabel(e event.Event) string { |
| 20 | if e.Kind == kindSite { |
| 21 | if _, err := nostr.PubKeyFromHex(e.PubKey); err != nil { |
| 22 | return "" |
| 23 | } |
| 24 | return identityNpub(e.PubKey) |
| 25 | } |
| 26 | key, prefix, suffix := e.PubKey, "" , event.Tag(e, "d" ) |
| 27 | switch e.Kind { |
| 28 | case kindNamedSite: |
| 29 | case kindSiteSnapshot: |
| 30 | key, prefix, suffix = e.ID, "v" , "" |
| 31 | default: |
| 32 | return "" |
| 33 | } |
| 34 | if !eventIDPattern.MatchString(key) { |
| 35 | return "" |
| 36 | } |
| 37 | n, ok := new(big.Int).SetString(key, 16) |
| 38 | if !ok { |
| 39 | return "" |
| 40 | } |
| 41 | label := n.Text(36) |
| 42 | return prefix + strings.Repeat("0" , 50-len(label)) + label + suffix |
| 43 | } |
| 44 | |
| 45 | func sitePathCount(e event.Event) int { |
| 46 | count := 0 |
| 47 | for _, tag := range e.Tags { |
| 48 | if len(tag) > 0 && tag[0] == "path" { |
| 49 | count++ |
| 50 | } |
| 51 | } |
| 52 | return count |
| 53 | } |