aboutsummaryrefslogtreecommitdiff
path: root/client.go
diff options
context:
space:
mode:
authorFChannel <>2021-07-30 17:47:45 -0700
committerFChannel <>2021-07-30 17:47:45 -0700
commitf0ce5bc6d4146bc1191b8f8428c387a9085217e5 (patch)
tree4df91733e71859fef5195c6eac9455c7d87ab005 /client.go
parentb413f9a7d72284a05d8802f06c51e4a23771d95d (diff)
removed shortImg and convertSize javascript to serverside
Diffstat (limited to 'client.go')
-rw-r--r--client.go61
1 files changed, 60 insertions, 1 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), `/\&lt;`, ">")
@@ -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), `/\&lt;`, ">")
@@ -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;
+}