From e80fe14f7985f9e85bfb9582926acd7891455786 Mon Sep 17 00:00:00 2001 From: FChannel <> Date: Sun, 1 May 2022 12:13:25 -0700 Subject: fix for parsing reply link and showing images in static folder --- post/util.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'post') 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, "'", "'") + content = strings.ReplaceAll(content, "\"", """) + content = strings.ReplaceAll(content, ">", `/\<`) + + return content +} + func ParseOptions(ctx *fiber.Ctx, obj activitypub.ObjectBase) activitypub.ObjectBase { options := util.EscapeString(ctx.FormValue("options")) if options != "" { -- cgit v1.2.3