diff options
author | FChannel <> | 2021-07-22 15:14:14 -0700 |
---|---|---|
committer | FChannel <> | 2021-07-22 15:14:14 -0700 |
commit | fa895350a8bdf2eb93495dbf569fa3fe0680d2af (patch) | |
tree | f06951a0f115bb0e0bfddf7e5d9773d3b1d76492 | |
parent | 3b2c8a4c78ade9e819b61aa055039ae00e517a3e (diff) |
removed media javascript parsing it on server
-rw-r--r-- | client.go | 86 | ||||
-rw-r--r-- | static/ncatalog.html | 46 | ||||
-rw-r--r-- | static/posts.html | 86 |
3 files changed, 90 insertions, 128 deletions
@@ -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 = "<img " + media += "id=\"img\" " + media += "main=\"1\" " + media += "enlarge=\"0\" " + media += "attachment=\"" + obj.Attachment[0].Href + "\"" + if catalog { + media += "style=\"max-width: 180px; max-height: 180px;\" " + } else { + media += "style=\"float: left; margin-right: 10px; margin-bottom: 10px; max-width: 250px; max-height: 250px;\"" + } + if obj.Preview.Id != "" { + media += "src=\"" + MediaProxy(obj.Preview.Href) + "\"" + media += "preview=\"" + MediaProxy(obj.Preview.Href) + "\"" + } else { + media += "src=\"" + MediaProxy(obj.Attachment[0].Href) + "\"" + media += "preview=\"" + MediaProxy(obj.Attachment[0].Href) + "\"" + } + + media += ">" + + return template.HTML(media) + } + + if(regexp.MustCompile(`audio\/`).MatchString(obj.Attachment[0].MediaType)){ + media = "<audio " + media += "controls=\"controls\" " + media += "preload=\"metadta\" " + if catalog { + media += "style=\"margin-right: 10px; margin-bottom: 10px; max-width: 180px; max-height: 180px;\" " + } else { + media += "style=\"float: left; margin-right: 10px; margin-bottom: 10px; max-width: 250px; max-height: 250px;\" " + } + media += ">" + media += "<source " + media += "src=\"" + MediaProxy(obj.Attachment[0].Href) + "\" " + media += "type=\"" + obj.Attachment[0].MediaType + "\" " + media += ">" + media += "Audio is not supported." + media += "</audio>" + + return template.HTML(media) + } + + if(regexp.MustCompile(`video\/`).MatchString(obj.Attachment[0].MediaType)){ + media = "<video " + media += "controls=\"controls\" " + media += "preload=\"metadta\" " + media += "muted=\"muted\" " + if catalog { + media += "style=\"margin-right: 10px; margin-bottom: 10px; max-width: 180px; max-height: 180px;\" " + } else { + media += "style=\"float: left; margin-right: 10px; margin-bottom: 10px; max-width: 250px; max-height: 250px;\" " + } + media += ">" + media += "<source " + media += "src=\"" + MediaProxy(obj.Attachment[0].Href) + "\" " + media += "type=\"" + obj.Attachment[0].MediaType + "\" " + media += ">" + media += "Video is not supported." + media += "</video>" + + return template.HTML(media) + } + + return template.HTML(media) +} diff --git a/static/ncatalog.html b/static/ncatalog.html index d007d62..c7f5b30 100644 --- a/static/ncatalog.html +++ b/static/ncatalog.html @@ -37,8 +37,8 @@ {{ end }} <div id="hide-{{ .Id }}" style="display: none;">[Hide]</div> <div id="sensitive-{{ .Id }}" style="display: none;"><div style="position: relative; text-align: center;"><img id="sensitive-img-{{ .Id }}" style="float: left; margin-right: 10px; margin-bottom: 10px; max-width: 180px; max-height: 180px;" src="/static/sensitive.png"><div id="sensitive-text-{{ .Id }}" style="width: 170px; position: absolute; margin-top: 75px; padding: 5px; background-color: black; color: white; cursor: default; ">NSFW Content</div></div></div> - <a id="{{ .Id }}-anchor" href="/{{ $board.Name }}/"> - <div id="media-{{ .Id }}" style="width:180px;"></div> + <a id="{{ .Id }}-anchor" href="/{{ $board.Name }}/{{ short $board.Actor.Outbox .Id}}"> + <div id="media-{{ .Id }}" style="width:180px;"> {{ parseAttachment . true }}</div> </a> <script> media = document.getElementById("media-{{ .Id }}") @@ -61,48 +61,6 @@ sensitive.style = "display: block" media.style = "display: none;" } - - if(getMIMEType({{ (index .Attachment 0).MediaType }}) == "image"){ - var img = document.createElement("img"); - img.style = "max-width: 180px; max-height: 180px;" - img.setAttribute("id", "img") - img.setAttribute("main", "1") - img.setAttribute("enlarge", "0") - img.setAttribute("attachment", "{{ proxy (index .Attachment 0).Href }}") - {{ if .Preview.Href }} - img.setAttribute("src", "{{ proxy .Preview.Href }}") - img.setAttribute("preview", "{{ proxy .Preview.Href }}") - {{ else }} - img.setAttribute("src", "{{ proxy (index .Attachment 0).Href }}") - img.setAttribute("preview", "{{ proxy (index .Attachment 0).Href }}") - {{ end }} - media.appendChild(img) - } - - if(getMIMEType({{ (index .Attachment 0).MediaType }}) == "audio"){ - var audio = document.createElement("audio") - audio.controls = 'controls' - audio.preload = 'metadata' - audio.src = '{{ proxy (index .Attachment 0).Href }}' - audio.type = '{{ (index .Attachment 0).MediaType }}' - audio.style = "margin-right: 10px; margin-bottom: 10px; max-width: 180px; max-height: 180px;" - audio.innerText = 'Audio is not supported.' - media.appendChild(audio) - } - - if(getMIMEType({{ (index .Attachment 0).MediaType }}) == "video"){ - var video = document.createElement("video") - video.controls = 'controls' - video.preload = 'metadata' - video.muted = 'muted' - video.src = '{{ proxy (index .Attachment 0).Href }}' - video.type = '{{ (index .Attachment 0).MediaType }}' - video.style = "margin-right: 10px; margin-bottom: 10px; max-width: 180px; max-height: 180px;" - video.innerText = 'Video is not supported.' - media.appendChild(video) - } - - document.getElementById("{{ .Id }}-anchor").href = "/{{ $board.Name }}/" + shortURL("{{$board.Actor.Id}}", "{{ .Id }}") </script> {{ end }} <a id="{{ .Id }}-link" href="/{{ $board.Name }}/{{ short $board.Actor.Outbox .Id }}"> 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 @@ <span style="display: block;">File: <a id="{{ .Id }}-img" href="{{ proxy (index .Attachment 0).Href}}">{{ (index .Attachment 0).Name }}</a><span id="{{ .Id }}-size">({{ (index .Attachment 0).Size }})</span></span> <div id="hide-{{ .Id }}" style="display: none;">[Hide]</div> <div id="sensitive-{{ .Id }}" style="display: none;"><div style="position: relative; text-align: center;"><img id="sensitive-img-{{ .Id }}" style="float: left; margin-right: 10px; margin-bottom: 10px; max-width: 250px; max-height: 250px;" src="/static/sensitive.png"><div id="sensitive-text-{{ .Id }}" style="width: 240px; position: absolute; margin-top: 110px; padding: 5px; background-color: black; color: white; cursor: default; ">NSFW Content</div></div></div> - <div id="media-{{ .Id }}"></div> + <div id="media-{{ .Id }}">{{ parseAttachment . false }}</div> <script> media = document.getElementById("media-{{ .Id }}") if(({{ .Sensitive }} && {{ $board.Actor.Restricted }}) || (isOnion("{{ .Id }}") && !isOnion("{{ $board.Domain }}"))){ @@ -41,46 +41,7 @@ sensitive.style = "display: block" media.style = "display: none;" } - - if(getMIMEType({{ (index .Attachment 0).MediaType }}) == "image"){ - var img = document.createElement("img"); - img.style = "float: left; margin-right: 10px; margin-bottom: 10px; max-width: 250px; max-height: 250px;" - img.setAttribute("id", "img") - img.setAttribute("main", "1") - img.setAttribute("enlarge", "0") - img.setAttribute("attachment", "{{ proxy (index .Attachment 0).Href }}") - {{ if .Preview.Href }} - img.setAttribute("src", "{{ proxy .Preview.Href }}") - img.setAttribute("preview", "{{ proxy .Preview.Href }}") - {{ else }} - img.setAttribute("src", "{{ proxy (index .Attachment 0).Href }}") - img.setAttribute("preview", "{{ proxy (index .Attachment 0).Href }}") - {{ end }} - media.appendChild(img) - } - - if(getMIMEType({{ (index .Attachment 0).MediaType }}) == "audio"){ - var audio = document.createElement("audio") - audio.controls = 'controls' - audio.preload = 'metadata' - audio.src = '{{ proxy (index .Attachment 0).Href }}' - audio.type = '{{ (index .Attachment 0).MediaType }}' - audio.style = "float: left; margin-right: 10px; margin-bottom: 10px; max-width: 250px; max-height: 250px;" - audio.innerText = 'Audio is not supported.' - media.appendChild(audio) - } - - if(getMIMEType({{ (index .Attachment 0).MediaType }}) == "video"){ - var video = document.createElement("video") - video.controls = 'controls' - video.preload = 'metadata' - video.muted = 'muted' - video.src = '{{ proxy (index .Attachment 0).Href }}' - video.type = '{{ (index .Attachment 0).MediaType }}' - video.style = "float: left; margin-right: 10px; margin-bottom: 10px; max-width: 250px; max-height: 250px;" - video.innerText = 'Video is not supported.' - media.appendChild(video) - } + </script> {{ end }} <span style="color: #0f0c5d;"><b>{{ .Name }}</b></span><span style="color: #117743;"><b>{{ if .AttributedTo }} {{.AttributedTo }} {{ else }} Anonymous {{ end }}</b></span><span class="tripcode"> {{ .TripCode }} </span><span>{{ .Published }} <a id="{{ .Id }}-anchor" href="/{{ $board.Name }}/{{ short $board.Actor.Outbox $opId }}#{{ short $board.Actor.Outbox .Id }}">No.</a> <a id="{{ .Id }}-link" title="{{ .Id }}" href="javascript:quote('{{ $board.Actor.Id }}', '{{ $opId }}', '{{ .Id }}')">{{ short $board.Actor.Outbox .Id }}</a> {{ if ne .Type "Tombstone" }}<a href="javascript:report('{{ $board.Actor.Id }}', '{{ .Id }}')">[Report]</a>{{ end }}</span> @@ -109,7 +70,7 @@ <div id="hide-{{ .Id }}" style="display: none;">[Hide]</div> <div id="sensitive-{{ .Id }}" style="display: none;"><div style="position: relative; text-align: center;"><img id="sensitive-img-{{ .Id }}" style="float: left; margin-right: 10px; margin-bottom: 10px; max-width: 250px; max-height: 250px;" src="/static/sensitive.png"><div id="sensitive-text-{{ .Id }}" style="width: 240px; position: absolute; margin-top: 110px; padding: 5px; background-color: black; color: white; cursor: default; ">NSFW Content</div></div></div> <div> </div> - <div id="media-{{ .Id }}" sensitive="0"></div> + <div id="media-{{ .Id }}" sensitive="0">{{ parseAttachment . false }}</div> <script> media = document.getElementById("media-{{ .Id }}") @@ -132,47 +93,6 @@ sensitive.style = "display: block" media.style = "display: none;" } - - if(getMIMEType({{ (index .Attachment 0).MediaType }}) == "image"){ - var img = document.createElement("img"); - img.style = "float: left; margin-right: 10px; margin-bottom: 10px; max-width: 250px; max-height: 250px;" - img.setAttribute("id", "img") - img.setAttribute("main", "1") - img.setAttribute("enlarge", "0") - img.setAttribute("attachment", "{{ proxy (index .Attachment 0).Href }}") - img.setAttribute("post", "{{ .Id }}") - {{ if and .Preview.Href . }} - img.setAttribute("src", "{{ proxy .Preview.Href }}") - img.setAttribute("preview", "{{ proxy .Preview.Href }}") - {{ else }} - img.setAttribute("src", "{{ proxy (index .Attachment 0).Href }}") - img.setAttribute("preview", "{{ proxy (index .Attachment 0).Href }}") - {{ end }} - media.appendChild(img) - } - - if(getMIMEType({{ (index .Attachment 0).MediaType }}) == "audio"){ - var audio = document.createElement("audio") - audio.controls = 'controls' - audio.preload = 'metadata' - audio.src = '{{ proxy (index .Attachment 0).Href }}' - audio.type = '{{ (index .Attachment 0).MediaType }}' - audio.style = "float: left; margin-right: 10px; margin-bottom: 10px; max-width: 250px; max-height: 250px;" - audio.innerText = 'Audio is not supported.' - media.appendChild(audio) - } - - if(getMIMEType({{ (index .Attachment 0).MediaType }}) == "video"){ - var video = document.createElement("video") - video.controls = 'controls' - video.preload = 'metadata' - video.muted = 'muted' - video.src = '{{ proxy (index .Attachment 0).Href }}' - video.type = '{{ (index .Attachment 0).MediaType }}' - video.style = "float: left; margin-right: 10px; margin-bottom: 10px; max-width: 250px; max-height: 250px;" - video.innerText = 'Video is not supported.' - media.appendChild(video) - } </script> {{ end }} <span style="color: #0f0c5d;"><b>{{ .Name }}</b></span><span style="color: #117743;"><b>{{ if .AttributedTo }} {{.AttributedTo }} {{ else }} Anonymous {{ end }}</b></span><span class="tripcode"> {{ .TripCode }} </span><span>{{ .Published }} <a id="{{ .Id }}-anchor" href="/{{ $board.Name }}/{{ short $board.Actor.Outbox $opId }}#{{ short $board.Actor.Outbox .Id }}">No. </a><a id="{{ .Id }}-link" title="{{ .Id }}" href="javascript:quote('{{ $board.Actor.Id }}', '{{ $opId }}', '{{ .Id }}')">{{ short $board.Actor.Outbox .Id }}</a> {{ if ne .Type "Tombstone" }}<a href="javascript:report('{{ $board.Actor.Id }}', '{{ .Id }}')">[Report]</a>{{ end }}</span> |