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 --- README.md | 2 +- activitypub/actor.go | 2 +- client.go | 51 ++++++----------------------------------------- main.go | 13 +++++------- post/util.go | 39 ++++++++++++++++++++++++++++++++++++ views/js/posts.js | 2 +- views/partials/posts.html | 4 +--- 7 files changed, 54 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index 1b6081e..d827524 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Current things that will be implemented first are: - Other improvements will be made over time, first it needs to be as easy as possible for new instances to come online and connect with others reliably. Try and run your own instances and federate with one of the instances above. -Any contributions or suggestions are appreciated. Best way to give immediate feedback is the XMPP: `general@rooms.fchannel.org` or Matrix: `#fchan:matrix.org` +Any contributions or suggestions are appreciated. Best way to give immediate feedback is the XMPP: `xmpp:general@rooms.fchannel.org` or Matrix: `#fchan:matrix.org` ## Development To get started on hacking the code of FChannel, it is recommended you setup your diff --git a/activitypub/actor.go b/activitypub/actor.go index 70681d1..e837df5 100644 --- a/activitypub/actor.go +++ b/activitypub/actor.go @@ -484,7 +484,7 @@ func GetActorInstance(path string) (string, string) { } } - re = regexp.MustCompile(`(https?://)?(www)?([\w\d-_.:]+)(/|\s+|\r|\r\n)?$`) + re = regexp.MustCompile(`(https?://)(www)?([\w\d-_.:]+)(/|\s+|\r|\r\n)?$`) mainActor := re.MatchString(path) if mainActor { match := re.FindStringSubmatch(path) diff --git a/client.go b/client.go index a57c76d..e7cf792 100644 --- a/client.go +++ b/client.go @@ -8,6 +8,7 @@ import ( "github.com/FChannel0/FChannel-Server/activitypub" "github.com/FChannel0/FChannel-Server/config" "github.com/FChannel0/FChannel-Server/db" + "github.com/FChannel0/FChannel-Server/post" "github.com/FChannel0/FChannel-Server/util" "github.com/FChannel0/FChannel-Server/webfinger" _ "github.com/lib/pq" @@ -138,7 +139,7 @@ func ParseLinkComments(board activitypub.Actor, op string, content string, threa isOP = " (OP)" } - parsedLink := ConvertHashLink(domain, link) + parsedLink := post.ConvertHashLink(domain, link) //formate the hover title text var quoteTitle string @@ -146,11 +147,11 @@ func ParseLinkComments(board activitypub.Actor, op string, content string, threa // if the quoted content is local get it // else get it from the database if thread.Id == link { - quoteTitle = ParseLinkTitle(board.Outbox, op, thread.Content) + quoteTitle = post.ParseLinkTitle(board.Outbox, op, thread.Content) } else { for _, e := range thread.Replies.OrderedItems { if e.Id == parsedLink { - quoteTitle = ParseLinkTitle(board.Outbox, op, e.Content) + quoteTitle = post.ParseLinkTitle(board.Outbox, op, e.Content) break } } @@ -162,9 +163,9 @@ func ParseLinkComments(board activitypub.Actor, op string, content string, threa } if len(obj.OrderedItems) > 0 { - quoteTitle = ParseLinkTitle(board.Outbox, op, obj.OrderedItems[0].Content) + quoteTitle = post.ParseLinkTitle(board.Outbox, op, obj.OrderedItems[0].Content) } else { - quoteTitle = ParseLinkTitle(board.Outbox, op, parsedLink) + quoteTitle = post.ParseLinkTitle(board.Outbox, op, parsedLink) } } } @@ -191,32 +192,6 @@ func ParseLinkComments(board activitypub.Actor, op string, content string, threa return content, 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) - } - - // TODO: this drops more than we need to - content = strings.ReplaceAll(content, "'", "") - content = strings.ReplaceAll(content, "\"", "") - content = strings.ReplaceAll(content, ">", `/\<`) - - return content -} - func ParseCommentQuotes(content string) string { // replace quotes re := regexp.MustCompile(`((\r\n|\r|\n|^)>(.+)?[^\r\n])`) @@ -233,17 +208,3 @@ func ParseCommentQuotes(content string) string { return re.ReplaceAllString(content, "\r\n>") } - -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 -} diff --git a/main.go b/main.go index 125369a..bafa0ee 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "github.com/FChannel0/FChannel-Server/activitypub" "github.com/FChannel0/FChannel-Server/config" "github.com/FChannel0/FChannel-Server/db" + "github.com/FChannel0/FChannel-Server/post" "github.com/FChannel0/FChannel-Server/routes" "github.com/FChannel0/FChannel-Server/util" "github.com/FChannel0/FChannel-Server/webfinger" @@ -112,6 +113,7 @@ func main() { app.Use(logger.New()) app.Static("/static", "./views") + app.Static("/static", "./static") app.Static("/public", "./public") /* @@ -636,14 +638,9 @@ func TemplateFunctions(engine *html.Engine) { engine.AddFunc("isOnion", util.IsOnion) engine.AddFunc("parseReplyLink", func(actorId string, op string, id string, content string) template.HTML { - actor, err := webfinger.FingerActor(actorId) - if err != nil { - // TODO: figure out what to do here - panic(err) - } - - title := strings.ReplaceAll(ParseLinkTitle(actor.Id, op, content), `/\<`, ">") - link := fmt.Sprintf(">>%s", actor.Name, util.ShortURL(actor.Outbox, op), util.ShortURL(actor.Outbox, id), title, util.ShortURL(actor.Outbox, id)) + actor, _ := webfinger.FingerActor(actorId) + title := strings.ReplaceAll(post.ParseLinkTitle(actor.Id+"/", op, content), `/\<`, ">") + link := ">>" + util.ShortURL(actor.Outbox, id) + "" return template.HTML(link) }) 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 != "" { diff --git a/views/js/posts.js b/views/js/posts.js index 87f6228..5a9ab50 100644 --- a/views/js/posts.js +++ b/views/js/posts.js @@ -3,7 +3,7 @@ function startNewPost(){ el.style="display:none;"; el.setAttribute("state", "1"); document.getElementById("newpost").style = ""; - document.getElementById("stopTablePost").style = "display:unset;"; + document.getElementById("stopTablePost").style = "cursor: pointer; display:unset;"; sessionStorage.setItem("newpostState", true); } diff --git a/views/partials/posts.html b/views/partials/posts.html index a248650..14d4878 100644 --- a/views/partials/posts.html +++ b/views/partials/posts.html @@ -106,9 +106,7 @@ {{ $parentId := .Id }} {{ if .Replies.OrderedItems }} {{ range .Replies.OrderedItems }} - - - + {{ parseReplyLink $board.Actor.Id $opId .Id .Content }} {{ end }} {{ end }}

{{ parseContent $board.Actor $opId .Content $thread }}

-- cgit v1.2.3