mirror of
https://github.com/aljazceru/njump.git
synced 2025-12-17 06:14:22 +01:00
expose Kind1063Metadata fields and use that struct directly in templates.
This commit is contained in:
70
data.go
70
data.go
@@ -90,18 +90,30 @@ type Data struct {
|
||||
}
|
||||
|
||||
type Kind1063Metadata struct {
|
||||
magnet string
|
||||
dim string
|
||||
size string
|
||||
summary string
|
||||
image string
|
||||
url string
|
||||
aes256gcm string
|
||||
m string
|
||||
x string
|
||||
i string
|
||||
blurhash string
|
||||
thumb string
|
||||
Magnet string
|
||||
Dim string
|
||||
Size string
|
||||
Summary string
|
||||
Image string
|
||||
URL string
|
||||
AES256GCM string
|
||||
M string
|
||||
X string
|
||||
I string
|
||||
Blurhash string
|
||||
Thumb string
|
||||
}
|
||||
|
||||
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 ""
|
||||
}
|
||||
}
|
||||
|
||||
func grabData(ctx context.Context, code string, isProfileSitemap bool) (*Data, error) {
|
||||
@@ -197,40 +209,40 @@ func grabData(ctx context.Context, code string, isProfileSitemap bool) (*Data, e
|
||||
data.kind1063Metadata = &Kind1063Metadata{}
|
||||
|
||||
if tag := event.Tags.GetFirst([]string{"url", ""}); tag != nil {
|
||||
data.kind1063Metadata.url = (*tag)[1]
|
||||
data.kind1063Metadata.URL = (*tag)[1]
|
||||
}
|
||||
if tag := event.Tags.GetFirst([]string{"m", ""}); tag != nil {
|
||||
data.kind1063Metadata.m = (*tag)[1]
|
||||
data.kind1063Metadata.M = (*tag)[1]
|
||||
}
|
||||
if tag := event.Tags.GetFirst([]string{"aes-256-gcm", ""}); tag != nil {
|
||||
data.kind1063Metadata.aes256gcm = (*tag)[1]
|
||||
data.kind1063Metadata.AES256GCM = (*tag)[1]
|
||||
}
|
||||
if tag := event.Tags.GetFirst([]string{"x", ""}); tag != nil {
|
||||
data.kind1063Metadata.x = (*tag)[1]
|
||||
data.kind1063Metadata.X = (*tag)[1]
|
||||
}
|
||||
if tag := event.Tags.GetFirst([]string{"size", ""}); tag != nil {
|
||||
data.kind1063Metadata.size = (*tag)[1]
|
||||
data.kind1063Metadata.Size = (*tag)[1]
|
||||
}
|
||||
if tag := event.Tags.GetFirst([]string{"dim", ""}); tag != nil {
|
||||
data.kind1063Metadata.dim = (*tag)[1]
|
||||
data.kind1063Metadata.Dim = (*tag)[1]
|
||||
}
|
||||
if tag := event.Tags.GetFirst([]string{"magnet", ""}); tag != nil {
|
||||
data.kind1063Metadata.magnet = (*tag)[1]
|
||||
data.kind1063Metadata.Magnet = (*tag)[1]
|
||||
}
|
||||
if tag := event.Tags.GetFirst([]string{"i", ""}); tag != nil {
|
||||
data.kind1063Metadata.i = (*tag)[1]
|
||||
data.kind1063Metadata.I = (*tag)[1]
|
||||
}
|
||||
if tag := event.Tags.GetFirst([]string{"blurhash", ""}); tag != nil {
|
||||
data.kind1063Metadata.blurhash = (*tag)[1]
|
||||
data.kind1063Metadata.Blurhash = (*tag)[1]
|
||||
}
|
||||
if tag := event.Tags.GetFirst([]string{"thumb", ""}); tag != nil {
|
||||
data.kind1063Metadata.thumb = (*tag)[1]
|
||||
data.kind1063Metadata.Thumb = (*tag)[1]
|
||||
}
|
||||
if tag := event.Tags.GetFirst([]string{"image", ""}); tag != nil {
|
||||
data.kind1063Metadata.image = (*tag)[1]
|
||||
data.kind1063Metadata.Image = (*tag)[1]
|
||||
}
|
||||
if tag := event.Tags.GetFirst([]string{"summary", ""}); tag != nil {
|
||||
data.kind1063Metadata.summary = (*tag)[1]
|
||||
data.kind1063Metadata.Summary = (*tag)[1]
|
||||
}
|
||||
default:
|
||||
if event.Kind >= 30000 && event.Kind < 40000 {
|
||||
@@ -258,11 +270,11 @@ func grabData(ctx context.Context, code string, isProfileSitemap bool) (*Data, e
|
||||
data.kindNIP = kindNIPs[event.Kind]
|
||||
|
||||
if event.Kind == 1063 {
|
||||
if strings.HasPrefix(data.kind1063Metadata.m, "image") {
|
||||
data.image = data.kind1063Metadata.url
|
||||
} else if strings.HasPrefix(data.kind1063Metadata.m, "video") {
|
||||
data.video = data.kind1063Metadata.url
|
||||
data.videoType = strings.Split(data.kind1063Metadata.m, "/")[1]
|
||||
if data.kind1063Metadata.IsImage() {
|
||||
data.image = data.kind1063Metadata.URL
|
||||
} else if data.kind1063Metadata.IsVideo() {
|
||||
data.video = data.kind1063Metadata.URL
|
||||
data.videoType = strings.Split(data.kind1063Metadata.M, "/")[1]
|
||||
}
|
||||
} else {
|
||||
urls := urlMatcher.FindAllString(event.Content, -1)
|
||||
|
||||
27
pages.go
27
pages.go
@@ -90,10 +90,9 @@ type DetailsPartial struct {
|
||||
Kind int
|
||||
KindNIP string
|
||||
KindDescription string
|
||||
Magnet string
|
||||
Dim string
|
||||
Size string
|
||||
Summary string
|
||||
|
||||
// kind-specific stuff
|
||||
FileMetadata *Kind1063Metadata
|
||||
}
|
||||
|
||||
func (*DetailsPartial) TemplateText() string { return tmplDetails }
|
||||
@@ -284,23 +283,11 @@ type FileMetadataPage struct {
|
||||
Style Style
|
||||
Subject string
|
||||
TitleizedContent string
|
||||
Alt string
|
||||
|
||||
// Specific Metadata
|
||||
Url string
|
||||
M string
|
||||
Aes256Gcm string
|
||||
X string
|
||||
Size string
|
||||
Dim string
|
||||
Magnet string
|
||||
I string
|
||||
Blurhash string
|
||||
Thumb string
|
||||
Image string
|
||||
Summary string
|
||||
Alt string
|
||||
|
||||
MType string // The first part of the mime type M
|
||||
FileMetadata Kind1063Metadata
|
||||
IsImage bool
|
||||
IsVideo bool
|
||||
}
|
||||
|
||||
func (*FileMetadataPage) TemplateText() string { return tmplFileMetadata }
|
||||
|
||||
@@ -231,10 +231,9 @@ func renderEvent(w http.ResponseWriter, r *http.Request) {
|
||||
SeenOn: data.relays,
|
||||
Npub: data.npub,
|
||||
Nprofile: data.nprofile,
|
||||
Magnet: data.kind1063Metadata.magnet,
|
||||
Dim: data.kind1063Metadata.dim,
|
||||
Size: data.kind1063Metadata.size,
|
||||
Summary: data.kind1063Metadata.summary,
|
||||
|
||||
// kind-specific stuff
|
||||
FileMetadata: data.kind1063Metadata,
|
||||
}
|
||||
|
||||
switch data.templateId {
|
||||
@@ -288,10 +287,6 @@ func renderEvent(w http.ResponseWriter, r *http.Request) {
|
||||
TitleizedContent: titleizedContent,
|
||||
})
|
||||
case FileMetadata:
|
||||
thisImage := data.kind1063Metadata.image
|
||||
if thisImage == "" && data.image != "" {
|
||||
thisImage = data.image
|
||||
}
|
||||
err = FileMetadataTemplate.Render(w, &FileMetadataPage{
|
||||
OpenGraphPartial: OpenGraphPartial{
|
||||
IsTwitter: style == StyleTwitter,
|
||||
@@ -302,7 +297,7 @@ func renderEvent(w http.ResponseWriter, r *http.Request) {
|
||||
TextImageURL: textImageURL,
|
||||
Video: data.video,
|
||||
VideoType: data.videoType,
|
||||
Image: thisImage,
|
||||
Image: data.kind1063Metadata.DisplayImage(),
|
||||
Description: description,
|
||||
AuthorLong: data.authorLong,
|
||||
},
|
||||
@@ -324,16 +319,11 @@ func renderEvent(w http.ResponseWriter, r *http.Request) {
|
||||
Style: style,
|
||||
Subject: subject,
|
||||
TitleizedContent: titleizedContent,
|
||||
Url: data.kind1063Metadata.url,
|
||||
M: data.kind1063Metadata.m,
|
||||
Aes256Gcm: data.kind1063Metadata.aes256gcm,
|
||||
X: data.kind1063Metadata.x,
|
||||
I: data.kind1063Metadata.i,
|
||||
Blurhash: data.kind1063Metadata.blurhash,
|
||||
Thumb: data.kind1063Metadata.thumb,
|
||||
Image: thisImage,
|
||||
Alt: data.alt,
|
||||
MType: strings.Split(data.kind1063Metadata.m, "/")[0],
|
||||
|
||||
FileMetadata: *data.kind1063Metadata,
|
||||
IsImage: data.kind1063Metadata.IsImage(),
|
||||
IsVideo: data.kind1063Metadata.IsVideo(),
|
||||
})
|
||||
case Other:
|
||||
err = OtherTemplate.Render(w, &OtherPage{
|
||||
|
||||
@@ -4,41 +4,47 @@
|
||||
></div>
|
||||
|
||||
{{ if not (eq "" .Npub) }}
|
||||
<div class="mb-6 leading-5 break-all">
|
||||
<div class="mb-6 break-all leading-5">
|
||||
<div class="text-sm text-strongpink">Author Public Key</div>
|
||||
{{.Npub}}
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
{{ if not (eq "" .Summary) }}
|
||||
<!------>
|
||||
|
||||
{{ if not (eq nil .FileMetadata) }}
|
||||
<!---->
|
||||
{{ if not (eq "" .FileMetadata.Summary) }}
|
||||
<div class="mb-6 leading-5">
|
||||
<div class="text-sm text-strongpink">Summary</div>
|
||||
{{.Summary}}
|
||||
{{.FileMetadata.Summary}}
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
{{ if not (eq "" .Dim) }}
|
||||
<!---->
|
||||
{{ if not (eq "" .FileMetadata.Dim) }}
|
||||
<div class="mb-6 leading-5">
|
||||
<div class="text-sm text-strongpink">Dimension</div>
|
||||
{{.Dim}}
|
||||
{{.FileMetadata.Dim}}
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
{{ if not (eq "" .Size) }}
|
||||
<!---->
|
||||
{{ if not (eq "" .FileMetadata.Size) }}
|
||||
<div class="mb-6 leading-5">
|
||||
<div class="text-sm text-strongpink">Size</div>
|
||||
{{.Size}} bytes
|
||||
{{.FileMetadata.Size}} bytes
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
{{ if not (eq "" .Magnet) }}
|
||||
<!---->
|
||||
{{ if not (eq "" .FileMetadata.Magnet) }}
|
||||
<div class="mb-6 leading-5">
|
||||
<div class="text-sm text-strongpink">Magnet URL</div>
|
||||
{{.Magnet}}
|
||||
{{.FileMetadata.Magnet}}
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
<!---->
|
||||
{{ end }}
|
||||
|
||||
<!------>
|
||||
|
||||
{{ if not (eq 0 (len .SeenOn)) }}
|
||||
<div class="mb-6 leading-5">
|
||||
@@ -120,7 +126,7 @@
|
||||
</div>
|
||||
|
||||
{{ if not (eq "" .Nprofile) }}
|
||||
<div class="mb-6 leading-5 break-all">
|
||||
<div class="mb-6 break-all leading-5">
|
||||
<div class="text-sm text-strongpink">Author Profile Code</div>
|
||||
{{.Nprofile}}
|
||||
</div>
|
||||
|
||||
@@ -65,22 +65,22 @@
|
||||
{{ end }}
|
||||
<!-- main content -->
|
||||
|
||||
{{ if (not (eq "" .Image))}}
|
||||
<img src="{{ .Image }}" alt="{{ .Alt }}" />
|
||||
{{ else if (eq "image" .MType)}}
|
||||
<img src="{{ .Url }}" alt="{{ .Alt }}" />
|
||||
{{ else if (eq "video" .MType)}}
|
||||
{{ if (not (eq "" .FileMetadata.Image))}}
|
||||
<img src="{{ .FileMetadata.Image }}" alt="{{ .Alt }}" />
|
||||
{{ else if .IsImage }}
|
||||
<img src="{{ .FileMetadata.URL }}" alt="{{ .Alt }}" />
|
||||
{{ else if .IsVideo }}
|
||||
<video
|
||||
controls
|
||||
width="100%%"
|
||||
class="max-h-[90vh] bg-neutral-300 dark:bg-zinc-700"
|
||||
>
|
||||
<source src="{{ .Url }}" alt="{{ .Alt }}" />
|
||||
<source src="{{ .FileMetadata.URL }}" alt="{{ .Alt }}" />
|
||||
</video>
|
||||
{{ end }}
|
||||
|
||||
<a
|
||||
href="{{ .Url }}"
|
||||
href="{{ .FileMetadata.URL }}"
|
||||
target="_new"
|
||||
class="not-prose mx-auto mb-3 block block w-2/6 basis-full rounded-lg border-0 bg-strongpink px-4 py-2 text-center text-center text-[17px] font-light font-normal text-white no-underline"
|
||||
>Download file</a
|
||||
|
||||
Reference in New Issue
Block a user