aboutsummaryrefslogtreecommitdiff
path: root/post
diff options
context:
space:
mode:
authorFChannel <>2022-05-01 12:13:25 -0700
committerFChannel <>2022-06-19 12:53:29 -0700
commite80fe14f7985f9e85bfb9582926acd7891455786 (patch)
tree80f4fb97c3299d94cb590a23be2eb531ec66c3db /post
parent2af4a39ac16c6245f0e87ddf3cc137339f6c604f (diff)
fix for parsing reply link and showing images in static folder
Diffstat (limited to 'post')
-rw-r--r--post/util.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/post/util.go b/post/util.go
index 0b87d42..a9d326a 100644
--- a/post/util.go
+++ b/post/util.go
@@ -17,6 +17,20 @@ import (
"github.com/gofiber/fiber/v2"
)
+func ConvertHashLink(domain string, link string) string {
+ re := regexp.MustCompile(`(#.+)`)
+ parsedLink := re.FindString(link)
+
+ if parsedLink != "" {
+ parsedLink = domain + "" + strings.Replace(parsedLink, "#", "", 1)
+ parsedLink = strings.Replace(parsedLink, "\r", "", -1)
+ } else {
+ parsedLink = link
+ }
+
+ return parsedLink
+}
+
func ParseCommentForReplies(comment string, op string) ([]activitypub.ObjectBase, error) {
re := regexp.MustCompile(`(>>(https?://[A-Za-z0-9_.:\-~]+\/[A-Za-z0-9_.\-~]+\/)(f[A-Za-z0-9_.\-~]+-)?([A-Za-z0-9_.\-~]+)?#?([A-Za-z0-9_.\-~]+)?)`)
match := re.FindAllStringSubmatch(comment, -1)
@@ -82,6 +96,31 @@ func ParseCommentForReply(comment string) (string, error) {
return "", nil
}
+func ParseLinkTitle(actorName string, op string, content string) string {
+ re := regexp.MustCompile(`(>>(https?://[A-Za-z0-9_.:\-~]+\/[A-Za-z0-9_.\-~]+\/)\w+(#.+)?)`)
+ match := re.FindAllStringSubmatch(content, -1)
+
+ for i, _ := range match {
+ link := strings.Replace(match[i][0], ">>", "", 1)
+ isOP := ""
+
+ domain := match[i][2]
+
+ if link == op {
+ isOP = " (OP)"
+ }
+
+ link = ConvertHashLink(domain, link)
+ content = strings.Replace(content, match[i][0], ">>"+util.ShortURL(actorName, link)+isOP, 1)
+ }
+
+ content = strings.ReplaceAll(content, "'", "&#39;")
+ content = strings.ReplaceAll(content, "\"", "&quot;")
+ content = strings.ReplaceAll(content, ">", `/\&lt;`)
+
+ return content
+}
+
func ParseOptions(ctx *fiber.Ctx, obj activitypub.ObjectBase) activitypub.ObjectBase {
options := util.EscapeString(ctx.FormValue("options"))
if options != "" {