From fa895350a8bdf2eb93495dbf569fa3fe0680d2af Mon Sep 17 00:00:00 2001 From: FChannel <> Date: Thu, 22 Jul 2021 15:14:14 -0700 Subject: removed media javascript parsing it on server --- client.go | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++- static/ncatalog.html | 46 ++-------------------------- static/posts.html | 86 ++-------------------------------------------------- 3 files changed, 90 insertions(+), 128 deletions(-) diff --git a/client.go b/client.go index 12e6147..5d824bf 100644 --- a/client.go +++ b/client.go @@ -190,7 +190,10 @@ func OutboxGet(w http.ResponseWriter, r *http.Request, db *sql.DB, collection Co }, "short": func(actorName string, url string) string { return shortURL(actorName, url) - }, + }, + "parseAttachment": func(obj ObjectBase, catalog bool) template.HTML { + return ParseAttachment(obj, catalog) + }, "sub": func (i, j int) int { return i - j }}).ParseFiles("./static/main.html", "./static/nposts.html", "./static/top.html", "./static/bottom.html", "./static/posts.html")) @@ -254,6 +257,9 @@ func CatalogGet(w http.ResponseWriter, r *http.Request, db *sql.DB, collection C }, "short": func(actorName string, url string) string { return shortURL(actorName, url) + }, + "parseAttachment": func(obj ObjectBase, catalog bool) template.HTML { + return ParseAttachment(obj, catalog) }, "sub": func (i, j int) int { return i - j }}).ParseFiles("./static/main.html", "./static/ncatalog.html", "./static/top.html")) actor := collection.Actor @@ -294,6 +300,9 @@ func PostGet(w http.ResponseWriter, r *http.Request, db *sql.DB){ }, "short": func(actorName string, url string) string { return shortURL(actorName, url) + }, + "parseAttachment": func(obj ObjectBase, catalog bool) template.HTML { + return ParseAttachment(obj, catalog) }, "sub": func (i, j int) int { return i - j }}).ParseFiles("./static/main.html", "./static/npost.html", "./static/top.html", "./static/bottom.html", "./static/posts.html")) @@ -702,3 +711,78 @@ func ParseContent(db *sql.DB, board Actor, op string, content string, thread Obj return template.HTML(nContent) } + +func ParseAttachment(obj ObjectBase, catalog bool) template.HTML { + + if len(obj.Attachment) < 1 { + return "" + } + + var media string + if(regexp.MustCompile(`image\/`).MatchString(obj.Attachment[0].MediaType)){ + media = "[Hide] - -
+
+
{{ parseAttachment . true }}
{{ end }} diff --git a/static/posts.html b/static/posts.html index 7552188..b638a10 100644 --- a/static/posts.html +++ b/static/posts.html @@ -19,7 +19,7 @@ File: {{ (index .Attachment 0).Name }}({{ (index .Attachment 0).Size }}) -
+
{{ parseAttachment . false }}
{{ end }} {{ .Name }}{{ if .AttributedTo }} {{.AttributedTo }} {{ else }} Anonymous {{ end }} {{ .TripCode }} {{ .Published }} No. {{ short $board.Actor.Outbox .Id }} {{ if ne .Type "Tombstone" }}[Report]{{ end }} @@ -109,7 +70,7 @@
-
+
{{ parseAttachment . false }}
{{ end }} {{ .Name }}{{ if .AttributedTo }} {{.AttributedTo }} {{ else }} Anonymous {{ end }} {{ .TripCode }} {{ .Published }} No. {{ short $board.Actor.Outbox .Id }} {{ if ne .Type "Tombstone" }}[Report]{{ end }} -- cgit v1.2.3