aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client.go61
-rw-r--r--static/js/posts.js116
-rw-r--r--static/posts.html16
3 files changed, 91 insertions, 102 deletions
diff --git a/client.go b/client.go
index e0bee0e..f6b2f96 100644
--- a/client.go
+++ b/client.go
@@ -10,6 +10,7 @@ import (
"sort"
"regexp"
"time"
+ "fmt"
)
var Key *string = new(string)
@@ -196,6 +197,12 @@ func OutboxGet(w http.ResponseWriter, r *http.Request, db *sql.DB, collection Co
"parseContent": func(board Actor, op string, content string, thread ObjectBase) template.HTML {
return ParseContent(db, board, op, content, thread)
},
+ "shortImg": func(url string) string {
+ return ShortImg(url)
+ },
+ "convertSize": func(size int64) string {
+ return ConvertSize(size)
+ },
"parseReplyLink": func(actorId string, op string, id string, content string) template.HTML {
actor := FingerActor(actorId)
title := strings.ReplaceAll(ParseLinkTitle(actor.Id, op, content), `/\<`, ">")
@@ -315,6 +322,12 @@ func PostGet(w http.ResponseWriter, r *http.Request, db *sql.DB){
"parseContent": func(board Actor, op string, content string, thread ObjectBase) template.HTML {
return ParseContent(db, board, op, content, thread)
},
+ "shortImg": func(url string) string {
+ return ShortImg(url)
+ },
+ "convertSize": func(size int64) string {
+ return ConvertSize(size)
+ },
"parseReplyLink": func(actorId string, op string, id string, content string) template.HTML {
actor := FingerActor(actorId)
title := strings.ReplaceAll(ParseLinkTitle(actor.Id, op, content), `/\<`, ">")
@@ -798,12 +811,15 @@ func ParseLinkComments(db *sql.DB, board Actor, op string, content string, threa
//this is a cross post
parsedOP := GetReplyOP(db, parsedLink)
+ actor := FingerActor(parsedLink)
if parsedOP != "" {
link = parsedOP + "#" + shortURL(parsedOP, parsedLink)
}
- content = strings.Replace(content, match[i][0], "<a class=\"reply\" style=\"" + style + "\" title=\"" + quoteTitle + "\" href=\"" + link + "\">&gt;&gt;" + shortURL(board.Outbox, parsedLink) + isOP + " →</a>", -1)
+ if actor.Id != "" {
+ content = strings.Replace(content, match[i][0], "<a class=\"reply\" style=\"" + style + "\" title=\"" + quoteTitle + "\" href=\"" + link + "\">&gt;&gt;" + shortURL(board.Outbox, parsedLink) + isOP + " →</a>", -1)
+ }
}
}
@@ -865,3 +881,46 @@ func ConvertHashLink(domain string, link string) string {
return parsedLink
}
+
+func ShortImg(url string) string {
+ nURL := url
+
+ re := regexp.MustCompile(`(\.\w+$)`)
+
+ fileName := re.ReplaceAllString(url, "")
+
+ if(len(fileName) > 26) {
+ re := regexp.MustCompile(`(^.{26})`)
+
+ match := re.FindStringSubmatch(fileName)
+
+ if len(match) > 0 {
+ nURL = match[0]
+ }
+
+ re = regexp.MustCompile(`(\..+$)`)
+
+ match = re.FindStringSubmatch(url)
+
+ if len(match) > 0 {
+ nURL = nURL + "(...)" + match[0];
+ }
+ }
+
+ return nURL;
+}
+
+func ConvertSize(size int64) string {
+ var rValue string
+
+ convert := float32(size) / 1024.0;
+
+ if(convert > 1024) {
+ convert = convert / 1024.0;
+ rValue = fmt.Sprintf("%.2f MB", convert)
+ } else {
+ rValue = fmt.Sprintf("%.2f KB", convert)
+ }
+
+ return rValue;
+}
diff --git a/static/js/posts.js b/static/js/posts.js
index d91fadd..9b8a743 100644
--- a/static/js/posts.js
+++ b/static/js/posts.js
@@ -2,14 +2,14 @@ function startNewPost(){
var el = document.getElementById("newpostbtn");
el.style="display:none;";
el.setAttribute("state", "1");
- document.getElementById("newpost").style = "display: block;";
+ document.getElementById("newpost").style = "display: block;";
}
function stopNewPost(){
var el = document.getElementById("newpostbtn");
el.style="display:block;";
el.setAttribute("state", "0");
- document.getElementById("newpost").style = "display: hidden;";
+ document.getElementById("newpost").style = "display: hidden;";
}
function newpost()
@@ -18,28 +18,22 @@ function newpost()
if(state === "0")
{
startNewPost();
- sessionStorage.setItem("newpostState", true);
+ sessionStorage.setItem("newpostState", true);
}
else
{
stopNewPost();
- sessionStorage.setItem("newpostState", false);
+ sessionStorage.setItem("newpostState", false);
}
}
-function getMIMEType(type)
-{
- re = /\/.+/g;
- return type.replace(re, "");
-}
-
function shortURL(actorName, url)
{
re = /.+\//g;
temp = re.exec(url);
var output;
-
+
if(stripTransferProtocol(temp[0]) == stripTransferProtocol(actorName) + "/")
{
var short = url.replace("https://", "");
@@ -50,7 +44,7 @@ function shortURL(actorName, url)
var u = re.exec(short);
- re = /\w+$/g;
+ re = /\w+$/g;
output = re.exec(short);
}else{
@@ -62,7 +56,7 @@ function shortURL(actorName, url)
var u = re.exec(short);
- re = /\w+$/g;
+ re = /\w+$/g;
u = re.exec(short);
@@ -71,7 +65,7 @@ function shortURL(actorName, url)
str = str.replace(u, " ").trim();
re = /(\w|[!@#$%^&*<>])+$/;
-
+
v = re.exec(str);
output = "f" + v[0] + "-" + u
@@ -80,40 +74,6 @@ function shortURL(actorName, url)
return output;
}
-function shortImg(url)
-{
- var u = url;
- if(url.length > 26)
- {
- var re = /^.{26}/g;
-
- u = re.exec(url);
-
- re = /\..+$/g;
-
- var v = re.exec(url);
-
- u += "(...)" + v;
- }
- return u;
-}
-
-function convertSize(size)
-{
- var convert = size / 1024.0;
- if(convert > 1024)
- {
- convert = convert / 1024.0;
- convert = convert.toFixed(2) + " MB";
- }
- else
- {
- convert = convert.toFixed(2) + " KB";
- }
-
- return convert;
-}
-
function getBoardId(url)
{
var re = /\/([^/\n]+)(.+)?/gm;
@@ -135,31 +95,31 @@ function convertContent(actorName, content, opid)
{
isOP = " (OP)";
}
-
+
var q = link;
-
+
if(document.getElementById(link + "-content") != null) {
q = document.getElementById(link + "-content").innerText;
q = q.replaceAll('>', '/\>');
q = q.replaceAll('"', '');
- q = q.replaceAll("'", "");
+ q = q.replaceAll("'", "");
}
newContent = newContent.replace(quote, '<a class="reply" title="' + q + '" href="'+ (actorName) + "/" + shortURL(actorName, opid) + '#' + shortURL(actorName, link) + '";">>>' + shortURL(actorName, link) + isOP + '</a>');
- });
+ });
}
-
+
re = /^(\s+)?>.+/gm;
match = newContent.match(re);
if(match)
{
match.forEach(function(quote, i) {
-
+
newContent = newContent.replace(quote, '<span class="quote">' + quote + '</span>');
});
}
-
+
return newContent.replaceAll('/\>', '>');
}
@@ -177,15 +137,15 @@ function convertContentNoLink(actorName, content, opid)
{
isOP = " (OP)";
}
-
+
var q = link;
-
+
if(document.getElementById(link + "-content") != null) {
q = document.getElementById(link + "-content").innerText;
}
-
+
newContent = newContent.replace(quote, '>>' + shortURL(actorName, link) + isOP);
- });
+ });
}
newContent = newContent.replaceAll("'", "");
return newContent.replaceAll('"', '');
@@ -194,36 +154,19 @@ function convertContentNoLink(actorName, content, opid)
function closeReply()
{
document.getElementById("reply-box").style.display = "none";
- document.getElementById("reply-comment").value = "";
-
+ document.getElementById("reply-comment").value = "";
+
sessionStorage.setItem("element-closed-reply", true);
}
function closeReport()
{
document.getElementById("report-box").style.display = "none";
- document.getElementById("report-comment").value = "";
+ document.getElementById("report-comment").value = "";
sessionStorage.setItem("element-closed-report", true);
}
-
-function previous(actorName, page)
-{
- var prev = parseInt(page) - 1;
- if(prev < 0)
- prev = 0;
- window.location.href = "/" + actorName + "/" + prev;
-}
-
-function next(actorName, totalPage, page)
-{
- var next = parseInt(page) + 1;
- if(next > parseInt(totalPage))
- next = parseInt(totalPage);
- window.location.href = "/" + actorName + "/" + next;
-}
-
function quote(actorName, opid, id)
{
sessionStorage.setItem("element-closed-reply", false);
@@ -248,7 +191,7 @@ function quote(actorName, opid, id)
if (inReplyTo.value != opid)
comment.value = "";
-
+
header.innerText = "Replying to Thread No. " + shortURL(actorName, opid);
inReplyTo.value = opid;
sessionStorage.setItem("element-reply-actor", actorName);
@@ -258,7 +201,7 @@ function quote(actorName, opid, id)
comment.value += ">>" + id + "\n";
sessionStorage.setItem("element-reply-comment", comment.value);
- dragElement(header);
+ dragElement(header);
}
@@ -268,7 +211,7 @@ function report(actorName, id)
var box = document.getElementById("report-box");
var header = document.getElementById("report-header");
var comment = document.getElementById("report-comment");
- var inReplyTo = document.getElementById("report-inReplyTo-box");
+ var inReplyTo = document.getElementById("report-inReplyTo-box");
var w = window.innerWidth / 2 - 200;
var h = document.getElementById(id + "-content").offsetTop - 348;
@@ -284,8 +227,8 @@ function report(actorName, id)
sessionStorage.setItem("element-report-actor", actorName);
sessionStorage.setItem("element-report-id", id);
- dragElement(header);
-}
+ dragElement(header);
+}
var pos1, pos2, pos3, pos4;
var elmnt;
@@ -363,7 +306,7 @@ const stateLoadHandler = function(event){
comment.value = sessionStorage.getItem("element-report-comment");
box.setAttribute("style", sessionStorage.getItem("element-report-style"));
-
+
box.style.top = sessionStorage.getItem("report-top");
box.style.left = sessionStorage.getItem("report-left");
@@ -393,7 +336,7 @@ const stateLoadHandler = function(event){
pos4 = parseInt(sessionStorage.getItem("pos4"));
box.setAttribute("style", sessionStorage.getItem("element-reply-style"));
-
+
box.style.top = sessionStorage.getItem("reply-top");
box.style.left = sessionStorage.getItem("reply-left");
@@ -421,4 +364,3 @@ function isOnion(value){
return true;
return false;
}
-
diff --git a/static/posts.html b/static/posts.html
index 928a51d..8ee3844 100644
--- a/static/posts.html
+++ b/static/posts.html
@@ -18,7 +18,7 @@
<a href="/deleteattach?id={{ .Id }}&board={{ $board.Actor.Name }}">[Delete Attachment]</a>
<a href="/marksensitive?id={{ .Id }}&board={{ $board.Actor.Name }}">[Mark Sensitive]</a>
{{ end }}
- <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>
+ <span style="display: block;">File: <a id="{{ .Id }}-img" href="{{ proxy (index .Attachment 0).Href}}">{{ shortImg (index .Attachment 0).Name }}</a><span id="{{ .Id }}-size"> ({{ convertSize (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 }}">{{ parseAttachment . false }}</div>
@@ -68,7 +68,7 @@
<a href="/deleteattach?id={{ .Id }}&board={{ $board.Actor.Name }}">[Delete Attachment]</a>
<a href="/marksensitive?id={{ .Id }}&board={{ $board.Actor.Name }}">[Mark Sensitive]</a>
{{ end }}
- <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>
+ <span style="display: block;">File <a id="{{ .Id }}-img" href="{{ proxy (index .Attachment 0).Href}}">{{ shortImg (index .Attachment 0).Name }}</a> <span id="{{ .Id }}-size"> ({{ convertSize (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> </div>
@@ -108,21 +108,9 @@
</div>
</div>
</div>
- <script>
- {{ if .Attachment }}
- document.getElementById("{{ .Id }}-size").innerText = " (" + convertSize({{ (index .Attachment 0).Size }}) + ")";
- document.getElementById("{{ .Id }}-img").innerText = shortImg("{{ (index .Attachment 0).Name }}");
- {{ end }}
- </script>
{{ end }}
{{ end }}
</div>
</div>
-<script>
- {{ if .Attachment }}
- document.getElementById("{{ .Id }}-size").innerText = " (" + convertSize({{ (index .Attachment 0).Size }}) + ")";
- document.getElementById("{{ .Id }}-img").innerText = shortImg("{{ (index .Attachment 0).Name }}");
- {{ end }}
-</script>
{{ end }}
{{ end }}