aboutsummaryrefslogtreecommitdiff
path: root/routes/post.go
diff options
context:
space:
mode:
authorKushBlazingJudah <59340248+KushBlazingJudah@users.noreply.github.com>2021-11-07 00:32:39 -0300
committerFChannel <>2022-06-19 12:53:29 -0700
commit972223c992ca5aa5e5d93cff3b2ee4e30182025b (patch)
treeff61695c734852aeafdc0e872cc6f47085a8e787 /routes/post.go
parentbc9051fd1a17e793647cf309c973a7feefebd98f (diff)
restructuring part 5
Diffstat (limited to 'routes/post.go')
-rw-r--r--routes/post.go104
1 files changed, 104 insertions, 0 deletions
diff --git a/routes/post.go b/routes/post.go
new file mode 100644
index 0000000..41706c0
--- /dev/null
+++ b/routes/post.go
@@ -0,0 +1,104 @@
+package routes
+
+import (
+ "regexp"
+
+ "github.com/FChannel0/FChannel-Server/config"
+ "github.com/FChannel0/FChannel-Server/db"
+ "github.com/FChannel0/FChannel-Server/util"
+ "github.com/FChannel0/FChannel-Server/webfinger"
+ "github.com/gofiber/fiber/v2"
+)
+
+func PostGet(ctx *fiber.Ctx) error {
+ actor, err := db.GetActorByNameFromDB(ctx.Params("actor"))
+ if err != nil {
+ return err
+ }
+
+ postId := ctx.Params("post")
+
+ inReplyTo := actor.Id + "/" + postId
+
+ var returnData PageData
+ returnData.Board.Name = actor.Name
+ returnData.Board.PrefName = actor.PreferredUsername
+ returnData.Board.To = actor.Outbox
+ returnData.Board.Actor = actor
+ returnData.Board.Summary = actor.Summary
+ returnData.Board.ModCred, _ = getPassword(ctx)
+ returnData.Board.Domain = config.Domain
+ returnData.Board.Restricted = actor.Restricted
+ returnData.ReturnTo = "feed"
+
+ capt, err := db.GetRandomCaptcha()
+ if err != nil {
+ return err
+ }
+ returnData.Board.Captcha = config.Domain + "/" + capt
+ returnData.Board.CaptchaCode = util.GetCaptchaCode(returnData.Board.Captcha)
+
+ returnData.Instance, err = db.GetActorFromDB(config.Domain)
+ if err != nil {
+ return err
+ }
+
+ returnData.Title = "/" + returnData.Board.Name + "/ - " + returnData.Board.PrefName
+
+ returnData.Key = config.Key
+
+ returnData.Boards = db.Boards
+
+ re := regexp.MustCompile("f(\\w|[!@#$%^&*<>])+-(\\w|[!@#$%^&*<>])+")
+
+ if re.MatchString(postId) { // if non local actor post
+ name := util.GetActorFollowNameFromPath(postId)
+
+ followActors, err := webfinger.GetActorsFollowFromName(actor, name)
+ if err != nil {
+ return err
+ }
+
+ followCollection, err := db.GetActorsFollowPostFromId(followActors, postId)
+ if err != nil {
+ return err
+ }
+
+ if len(followCollection.OrderedItems) > 0 {
+ returnData.Board.InReplyTo = followCollection.OrderedItems[0].Id
+ returnData.Posts = append(returnData.Posts, followCollection.OrderedItems[0])
+
+ actor, err := webfinger.FingerActor(returnData.Board.InReplyTo)
+ if err != nil {
+ return err
+ }
+
+ returnData.Board.Post.Actor = actor.Id
+ }
+ } else {
+ collection, err := db.GetObjectByIDFromDB(inReplyTo)
+ if err != nil {
+ return err
+ }
+
+ if collection.Actor != nil {
+ returnData.Board.Post.Actor = collection.Actor.Id
+ returnData.Board.InReplyTo = inReplyTo
+
+ if len(collection.OrderedItems) > 0 {
+ returnData.Posts = append(returnData.Posts, collection.OrderedItems[0])
+ }
+ }
+ }
+
+ if len(returnData.Posts) > 0 {
+ returnData.PostId = util.ShortURL(returnData.Board.To, returnData.Posts[0].Id)
+ }
+
+ returnData.Themes = &config.Themes
+ returnData.ThemeCookie = getThemeCookie(ctx)
+
+ return ctx.Render("npost", fiber.Map{
+ "page": returnData,
+ }, "layouts/main")
+}