mirror of
https://github.com/aljazceru/njump.git
synced 2025-12-18 06:44:22 +01:00
move nip31, nip53, nip94 definitions to go-nostr and prepare for nip52.
This commit is contained in:
126
data.go
126
data.go
@@ -9,34 +9,37 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/nbd-wtf/go-nostr/nip19"
|
"github.com/nbd-wtf/go-nostr/nip19"
|
||||||
|
"github.com/nbd-wtf/go-nostr/nip31"
|
||||||
|
"github.com/nbd-wtf/go-nostr/nip53"
|
||||||
|
"github.com/nbd-wtf/go-nostr/nip94"
|
||||||
sdk "github.com/nbd-wtf/nostr-sdk"
|
sdk "github.com/nbd-wtf/nostr-sdk"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Data struct {
|
type Data struct {
|
||||||
templateId TemplateID
|
templateId TemplateID
|
||||||
event EnhancedEvent
|
event EnhancedEvent
|
||||||
nprofile string
|
nprofile string
|
||||||
nevent string
|
nevent string
|
||||||
neventNaked string
|
neventNaked string
|
||||||
naddr string
|
naddr string
|
||||||
naddrNaked string
|
naddrNaked string
|
||||||
createdAt string
|
createdAt string
|
||||||
modifiedAt string
|
modifiedAt string
|
||||||
parentLink template.HTML
|
parentLink template.HTML
|
||||||
metadata Metadata
|
metadata Metadata
|
||||||
authorRelays []string
|
authorRelays []string
|
||||||
authorLong string
|
authorLong string
|
||||||
renderableLastNotes []EnhancedEvent
|
renderableLastNotes []EnhancedEvent
|
||||||
kindDescription string
|
kindDescription string
|
||||||
kindNIP string
|
kindNIP string
|
||||||
video string
|
video string
|
||||||
videoType string
|
videoType string
|
||||||
image string
|
image string
|
||||||
content string
|
content string
|
||||||
alt string
|
alt string
|
||||||
kind1063Metadata *Kind1063Metadata
|
kind1063Metadata *Kind1063Metadata
|
||||||
kind30311Metadata *Kind30311Metadata
|
kind30311Metadata *Kind30311Metadata
|
||||||
kind1311Metadata *Kind1311Metadata
|
kind31922Or31923Metadata *Kind31922Or31923Metadata
|
||||||
}
|
}
|
||||||
|
|
||||||
func grabData(ctx context.Context, code string, isProfileSitemap bool) (*Data, error) {
|
func grabData(ctx context.Context, code string, isProfileSitemap bool) (*Data, error) {
|
||||||
@@ -85,9 +88,7 @@ func grabData(ctx context.Context, code string, isProfileSitemap bool) (*Data, e
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if tag := event.Tags.GetFirst([]string{"alt", ""}); tag != nil {
|
data.alt = nip31.GetAlt(*event)
|
||||||
data.alt = (*tag)[1]
|
|
||||||
}
|
|
||||||
|
|
||||||
switch event.Kind {
|
switch event.Kind {
|
||||||
case 0:
|
case 0:
|
||||||
@@ -132,76 +133,17 @@ func grabData(ctx context.Context, code string, isProfileSitemap bool) (*Data, e
|
|||||||
}
|
}
|
||||||
case 1063:
|
case 1063:
|
||||||
data.templateId = FileMetadata
|
data.templateId = FileMetadata
|
||||||
data.kind1063Metadata = &Kind1063Metadata{}
|
data.kind1063Metadata = &Kind1063Metadata{nip94.ParseFileMetadata(*event)}
|
||||||
|
|
||||||
if tag := event.Tags.GetFirst([]string{"url", ""}); tag != nil {
|
|
||||||
data.kind1063Metadata.URL = (*tag)[1]
|
|
||||||
}
|
|
||||||
if tag := event.Tags.GetFirst([]string{"m", ""}); tag != nil {
|
|
||||||
data.kind1063Metadata.M = (*tag)[1]
|
|
||||||
}
|
|
||||||
if tag := event.Tags.GetFirst([]string{"aes-256-gcm", ""}); tag != nil {
|
|
||||||
data.kind1063Metadata.AES256GCM = (*tag)[1]
|
|
||||||
}
|
|
||||||
if tag := event.Tags.GetFirst([]string{"x", ""}); tag != nil {
|
|
||||||
data.kind1063Metadata.X = (*tag)[1]
|
|
||||||
}
|
|
||||||
if tag := event.Tags.GetFirst([]string{"size", ""}); tag != nil {
|
|
||||||
data.kind1063Metadata.Size = (*tag)[1]
|
|
||||||
}
|
|
||||||
if tag := event.Tags.GetFirst([]string{"dim", ""}); tag != nil {
|
|
||||||
data.kind1063Metadata.Dim = (*tag)[1]
|
|
||||||
}
|
|
||||||
if tag := event.Tags.GetFirst([]string{"magnet", ""}); tag != nil {
|
|
||||||
data.kind1063Metadata.Magnet = (*tag)[1]
|
|
||||||
}
|
|
||||||
if tag := event.Tags.GetFirst([]string{"i", ""}); tag != nil {
|
|
||||||
data.kind1063Metadata.I = (*tag)[1]
|
|
||||||
}
|
|
||||||
if tag := event.Tags.GetFirst([]string{"blurhash", ""}); tag != nil {
|
|
||||||
data.kind1063Metadata.Blurhash = (*tag)[1]
|
|
||||||
}
|
|
||||||
if tag := event.Tags.GetFirst([]string{"thumb", ""}); tag != nil {
|
|
||||||
data.kind1063Metadata.Thumb = (*tag)[1]
|
|
||||||
}
|
|
||||||
if tag := event.Tags.GetFirst([]string{"image", ""}); tag != nil {
|
|
||||||
data.kind1063Metadata.Image = (*tag)[1]
|
|
||||||
data.image = (*tag)[1]
|
|
||||||
}
|
|
||||||
if tag := event.Tags.GetFirst([]string{"summary", ""}); tag != nil {
|
|
||||||
data.kind1063Metadata.Summary = (*tag)[1]
|
|
||||||
}
|
|
||||||
case 30311:
|
case 30311:
|
||||||
data.templateId = LiveEvent
|
data.templateId = LiveEvent
|
||||||
data.kind30311Metadata = &Kind30311Metadata{}
|
data.kind30311Metadata = &Kind30311Metadata{LiveEvent: nip53.ParseLiveEvent(*event)}
|
||||||
|
host := data.kind30311Metadata.GetHost()
|
||||||
if tag := event.Tags.GetFirst([]string{"title", ""}); tag != nil {
|
if host != nil {
|
||||||
data.kind30311Metadata.Title = (*tag)[1]
|
hostProfile := sdk.FetchProfileMetadata(ctx, pool, host.PubKey, data.event.relays...)
|
||||||
}
|
data.kind30311Metadata.Host = &hostProfile
|
||||||
if tag := event.Tags.GetFirst([]string{"summary", ""}); tag != nil {
|
|
||||||
data.kind30311Metadata.Summary = (*tag)[1]
|
|
||||||
}
|
|
||||||
if tag := event.Tags.GetFirst([]string{"image", ""}); tag != nil {
|
|
||||||
data.kind30311Metadata.Image = (*tag)[1]
|
|
||||||
data.image = (*tag)[1]
|
|
||||||
}
|
|
||||||
if tag := event.Tags.GetFirst([]string{"status", ""}); tag != nil {
|
|
||||||
data.kind30311Metadata.Status = (*tag)[1]
|
|
||||||
}
|
|
||||||
pTags := event.Tags.GetAll([]string{"p", ""})
|
|
||||||
for _, p := range pTags {
|
|
||||||
if p[3] == "host" {
|
|
||||||
data.kind30311Metadata.Host = sdk.FetchProfileMetadata(ctx, pool, p[1], data.event.relays...)
|
|
||||||
data.kind30311Metadata.HostNpub = data.kind30311Metadata.Host.Npub()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tTags := event.Tags.GetAll([]string{"t", ""})
|
|
||||||
for _, t := range tTags {
|
|
||||||
data.kind30311Metadata.Tags = append(data.kind30311Metadata.Tags, t[1])
|
|
||||||
}
|
}
|
||||||
case 1311:
|
case 1311:
|
||||||
data.templateId = LiveEventMessage
|
data.templateId = LiveEventMessage
|
||||||
data.kind1311Metadata = &Kind1311Metadata{}
|
|
||||||
data.content = event.Content
|
data.content = event.Content
|
||||||
if atag := event.Tags.GetFirst([]string{"a", ""}); atag != nil {
|
if atag := event.Tags.GetFirst([]string{"a", ""}); atag != nil {
|
||||||
parts := strings.Split((*atag)[1], ":")
|
parts := strings.Split((*atag)[1], ":")
|
||||||
|
|||||||
3
go.mod
3
go.mod
@@ -15,7 +15,7 @@ require (
|
|||||||
github.com/kelseyhightower/envconfig v1.4.0
|
github.com/kelseyhightower/envconfig v1.4.0
|
||||||
github.com/microcosm-cc/bluemonday v1.0.24
|
github.com/microcosm-cc/bluemonday v1.0.24
|
||||||
github.com/nbd-wtf/emoji v0.0.3
|
github.com/nbd-wtf/emoji v0.0.3
|
||||||
github.com/nbd-wtf/go-nostr v0.27.3
|
github.com/nbd-wtf/go-nostr v0.28.0
|
||||||
github.com/nbd-wtf/nostr-sdk v0.0.4
|
github.com/nbd-wtf/nostr-sdk v0.0.4
|
||||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
|
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
|
||||||
github.com/pelletier/go-toml v1.9.5
|
github.com/pelletier/go-toml v1.9.5
|
||||||
@@ -63,6 +63,7 @@ require (
|
|||||||
github.com/pkg/errors v0.9.1 // indirect
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/puzpuzpuz/xsync/v2 v2.5.1 // indirect
|
github.com/puzpuzpuz/xsync/v2 v2.5.1 // indirect
|
||||||
|
github.com/puzpuzpuz/xsync/v3 v3.0.2 // indirect
|
||||||
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee // indirect
|
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee // indirect
|
||||||
github.com/sebest/xff v0.0.0-20210106013422-671bd2870b3a // indirect
|
github.com/sebest/xff v0.0.0-20210106013422-671bd2870b3a // indirect
|
||||||
github.com/shopspring/decimal v1.3.1 // indirect
|
github.com/shopspring/decimal v1.3.1 // indirect
|
||||||
|
|||||||
6
go.sum
6
go.sum
@@ -159,8 +159,8 @@ github.com/microcosm-cc/bluemonday v1.0.24 h1:NGQoPtwGVcbGkKfvyYk1yRqknzBuoMiUrO
|
|||||||
github.com/microcosm-cc/bluemonday v1.0.24/go.mod h1:ArQySAMps0790cHSkdPEJ7bGkF2VePWH773hsJNSHf8=
|
github.com/microcosm-cc/bluemonday v1.0.24/go.mod h1:ArQySAMps0790cHSkdPEJ7bGkF2VePWH773hsJNSHf8=
|
||||||
github.com/nbd-wtf/emoji v0.0.3 h1:YtkT7MVPXvqU1SQjvC/CShlWexnREzqNCxmhUnL00CA=
|
github.com/nbd-wtf/emoji v0.0.3 h1:YtkT7MVPXvqU1SQjvC/CShlWexnREzqNCxmhUnL00CA=
|
||||||
github.com/nbd-wtf/emoji v0.0.3/go.mod h1:tS6D9iI34qwBmWc5g8X7tVDkWXulqbTJRsvsM6QsS88=
|
github.com/nbd-wtf/emoji v0.0.3/go.mod h1:tS6D9iI34qwBmWc5g8X7tVDkWXulqbTJRsvsM6QsS88=
|
||||||
github.com/nbd-wtf/go-nostr v0.27.3 h1:u9fdP5h+Ap3LcDFD2j6F2buU/xOM9ddMY0LCDcC6ZyY=
|
github.com/nbd-wtf/go-nostr v0.28.0 h1:SLYyoFeCNYb7HyWtmPUzD6rifBOMR66Spj5fzCk+5GE=
|
||||||
github.com/nbd-wtf/go-nostr v0.27.3/go.mod h1:e5WOFsKEpslDOxIgK00NqemH7KuAvKIW6sBXeJYCfUs=
|
github.com/nbd-wtf/go-nostr v0.28.0/go.mod h1:OQ8sNLFJnsj17BdqZiLSmjJBIFTfDqckEYC3utS4qoY=
|
||||||
github.com/nbd-wtf/nostr-sdk v0.0.4 h1:vMCiYpFElKMHPXpZjFVEq4utoTLdTYbkqXVYH1/4uzs=
|
github.com/nbd-wtf/nostr-sdk v0.0.4 h1:vMCiYpFElKMHPXpZjFVEq4utoTLdTYbkqXVYH1/4uzs=
|
||||||
github.com/nbd-wtf/nostr-sdk v0.0.4/go.mod h1:KQZOtzcrXBlVhpZYG1tw83ADIONNMMPjUU3ZAH5U2RY=
|
github.com/nbd-wtf/nostr-sdk v0.0.4/go.mod h1:KQZOtzcrXBlVhpZYG1tw83ADIONNMMPjUU3ZAH5U2RY=
|
||||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
|
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
|
||||||
@@ -185,6 +185,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
|
|||||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||||
github.com/puzpuzpuz/xsync/v2 v2.5.1 h1:mVGYAvzDSu52+zaGyNjC+24Xw2bQi3kTr4QJ6N9pIIU=
|
github.com/puzpuzpuz/xsync/v2 v2.5.1 h1:mVGYAvzDSu52+zaGyNjC+24Xw2bQi3kTr4QJ6N9pIIU=
|
||||||
github.com/puzpuzpuz/xsync/v2 v2.5.1/go.mod h1:gD2H2krq/w52MfPLE+Uy64TzJDVY7lP2znR9qmR35kU=
|
github.com/puzpuzpuz/xsync/v2 v2.5.1/go.mod h1:gD2H2krq/w52MfPLE+Uy64TzJDVY7lP2znR9qmR35kU=
|
||||||
|
github.com/puzpuzpuz/xsync/v3 v3.0.2 h1:3yESHrRFYr6xzkz61LLkvNiPFXxJEAABanTQpKbAaew=
|
||||||
|
github.com/puzpuzpuz/xsync/v3 v3.0.2/go.mod h1:VjzYrABPabuM4KyBh1Ftq6u8nhwY5tBPKP9jpmh0nnA=
|
||||||
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
|
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
|
||||||
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
|
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
|
||||||
github.com/rs/cors v1.10.0 h1:62NOS1h+r8p1mW6FM0FSB0exioXLhd/sh15KpjWBZ+8=
|
github.com/rs/cors v1.10.0 h1:62NOS1h+r8p1mW6FM0FSB0exioXLhd/sh15KpjWBZ+8=
|
||||||
|
|||||||
@@ -38,19 +38,19 @@ templ liveEventTemplate(params LiveEventPageParams) {
|
|||||||
}
|
}
|
||||||
</h1>
|
</h1>
|
||||||
<div class="mb-4">
|
<div class="mb-4">
|
||||||
if params.LiveEvent.HostNpub != "" {
|
if params.LiveEvent.Host != nil {
|
||||||
Streaming hosted by
|
Streaming hosted by
|
||||||
<a href={ templ.URL("/" + params.LiveEvent.HostNpub) }>
|
<a href={ templ.URL("/" + params.LiveEvent.Host.Npub()) }>
|
||||||
{ params.LiveEvent.Host.Name }
|
{ params.LiveEvent.Host.Name }
|
||||||
</a>
|
</a>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
<!-- main content -->
|
<!-- main content -->
|
||||||
<div class="mb-4">
|
<div class="mb-4">
|
||||||
for _, v := range params.LiveEvent.Tags {
|
for _, v := range params.LiveEvent.Hashtags {
|
||||||
<span
|
<span class="mr-2 whitespace-nowrap rounded bg-neutral-200 px-2 dark:bg-neutral-700 dark:text-white">
|
||||||
class="mr-2 whitespace-nowrap rounded bg-neutral-200 px-2 dark:bg-neutral-700 dark:text-white"
|
{ v }
|
||||||
>{ v }</span>
|
</span>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
if params.LiveEvent.Summary != "" {
|
if params.LiveEvent.Summary != "" {
|
||||||
|
|||||||
2
pages.go
2
pages.go
@@ -221,8 +221,6 @@ type LiveEventMessagePageParams struct {
|
|||||||
TitleizedContent string
|
TitleizedContent string
|
||||||
Alt string
|
Alt string
|
||||||
|
|
||||||
LiveEventMessage Kind1311Metadata
|
|
||||||
|
|
||||||
Clients []ClientReference
|
Clients []ClientReference
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -436,8 +436,6 @@ func renderEvent(w http.ResponseWriter, r *http.Request) {
|
|||||||
TitleizedContent: titleizedContent,
|
TitleizedContent: titleizedContent,
|
||||||
Alt: data.alt,
|
Alt: data.alt,
|
||||||
Clients: generateClientList(data.event.Kind, data.naddr),
|
Clients: generateClientList(data.event.Kind, data.naddr),
|
||||||
|
|
||||||
LiveEventMessage: *data.kind1311Metadata,
|
|
||||||
})
|
})
|
||||||
case Other:
|
case Other:
|
||||||
detailsData.HideDetails = false // always open this since we know nothing else about the event
|
detailsData.HideDetails = false // always open this since we know nothing else about the event
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ import (
|
|||||||
"github.com/nbd-wtf/go-nostr"
|
"github.com/nbd-wtf/go-nostr"
|
||||||
"github.com/nbd-wtf/go-nostr/nip10"
|
"github.com/nbd-wtf/go-nostr/nip10"
|
||||||
"github.com/nbd-wtf/go-nostr/nip19"
|
"github.com/nbd-wtf/go-nostr/nip19"
|
||||||
|
"github.com/nbd-wtf/go-nostr/nip52"
|
||||||
|
"github.com/nbd-wtf/go-nostr/nip53"
|
||||||
|
"github.com/nbd-wtf/go-nostr/nip94"
|
||||||
sdk "github.com/nbd-wtf/nostr-sdk"
|
sdk "github.com/nbd-wtf/nostr-sdk"
|
||||||
"github.com/texttheater/golang-levenshtein/levenshtein"
|
"github.com/texttheater/golang-levenshtein/levenshtein"
|
||||||
)
|
)
|
||||||
@@ -178,42 +181,14 @@ func (ee EnhancedEvent) ToJSONHTML() template.HTML {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Kind1063Metadata struct {
|
type Kind1063Metadata struct {
|
||||||
Magnet string
|
nip94.FileMetadata
|
||||||
Dim string
|
|
||||||
Size string
|
|
||||||
Summary string
|
|
||||||
Image string
|
|
||||||
URL string
|
|
||||||
AES256GCM string
|
|
||||||
M string
|
|
||||||
X string
|
|
||||||
I string
|
|
||||||
Blurhash string
|
|
||||||
Thumb string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Kind30311Metadata struct {
|
type Kind30311Metadata struct {
|
||||||
Title string
|
nip53.LiveEvent
|
||||||
Summary string
|
Host *sdk.ProfileMetadata
|
||||||
Image string
|
|
||||||
Status string
|
|
||||||
Host sdk.ProfileMetadata
|
|
||||||
HostNpub string
|
|
||||||
Tags []string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Kind1311Metadata struct {
|
type Kind31922Or31923Metadata struct {
|
||||||
// ...
|
nip52.CalendarEvent
|
||||||
}
|
|
||||||
|
|
||||||
func (fm Kind1063Metadata) IsVideo() bool { return strings.Split(fm.M, "/")[0] == "video" }
|
|
||||||
func (fm Kind1063Metadata) IsImage() bool { return strings.Split(fm.M, "/")[0] == "image" }
|
|
||||||
func (fm Kind1063Metadata) DisplayImage() string {
|
|
||||||
if fm.Image != "" {
|
|
||||||
return fm.Image
|
|
||||||
} else if fm.IsImage() {
|
|
||||||
return fm.URL
|
|
||||||
} else {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user