aboutsummaryrefslogtreecommitdiff
path: root/routes
diff options
context:
space:
mode:
Diffstat (limited to 'routes')
-rw-r--r--routes/index.go32
-rw-r--r--routes/outbox.go73
-rw-r--r--routes/post.go145
-rw-r--r--routes/structs.go8
4 files changed, 142 insertions, 116 deletions
diff --git a/routes/index.go b/routes/index.go
index 5ff2bd4..23b3f39 100644
--- a/routes/index.go
+++ b/routes/index.go
@@ -21,6 +21,21 @@ func Index(ctx *fiber.Ctx) error {
}
var data PageData
+
+ col, err := webfinger.GetCollectionFromReq("https://fchan.xyz/followers")
+ if err != nil {
+ return err
+ }
+
+ if len(col.Items) > 0 {
+ data.InstanceIndex = col.Items
+ }
+
+ data.NewsItems, err = db.GetNewsFromDB(3)
+ if err != nil {
+ return err
+ }
+
data.Title = "Welcome to " + actor.PreferredUsername
data.PreferredUsername = actor.PreferredUsername
data.Boards = db.Boards
@@ -34,23 +49,14 @@ func Index(ctx *fiber.Ctx) error {
//almost certainly there is a better algorithm for this but the old one was wrong
//and I suck at math. This works at least.
data.BoardRemainer = make([]int, 3-(len(data.Boards)%3))
+
if len(data.BoardRemainer) == 3 {
data.BoardRemainer = make([]int, 0)
}
- col, err := webfinger.GetCollectionFromReq("https://fchan.xyz/followers")
- if err != nil {
- return err
- }
-
- if len(col.Items) > 0 {
- data.InstanceIndex = col.Items
- }
-
- data.NewsItems, err = db.GetNewsFromDB(3)
- if err != nil {
- return err
- }
+ data.Meta.Description = data.PreferredUsername + " a federated image board based on ActivityPub. The current version of the code running on the server is still a work-in-progress product, expect a bumpy ride for the time being. Get the server code here: https://github.com/FChannel0."
+ data.Meta.Url = data.Board.Domain
+ data.Meta.Title = data.Title
data.Themes = &config.Themes
data.ThemeCookie = getThemeCookie(ctx)
diff --git a/routes/outbox.go b/routes/outbox.go
index 1277011..4b874df 100644
--- a/routes/outbox.go
+++ b/routes/outbox.go
@@ -41,36 +41,6 @@ func OutboxGet(ctx *fiber.Ctx) error {
}
}
- var returnData PageData
-
- returnData.Board.Name = actor.Name
- returnData.Board.PrefName = actor.PreferredUsername
- returnData.Board.Summary = actor.Summary
- returnData.Board.InReplyTo = ""
- returnData.Board.To = actor.Outbox
- returnData.Board.Actor = actor
- returnData.Board.ModCred, _ = getPassword(ctx)
- returnData.Board.Domain = config.Domain
- returnData.Board.Restricted = actor.Restricted
- returnData.CurrentPage = page
- returnData.ReturnTo = "feed"
-
- returnData.Board.Post.Actor = actor.Id
-
- capt, err := db.GetRandomCaptcha()
- if err != nil {
- return err
- }
- returnData.Board.Captcha = config.Domain + "/" + capt
- returnData.Board.CaptchaCode = util.GetCaptchaCode(returnData.Board.Captcha)
-
- returnData.Title = "/" + actor.Name + "/ - " + actor.PreferredUsername
-
- returnData.Key = config.Key
-
- returnData.Boards = db.Boards
- returnData.Posts = collection.OrderedItems
-
var offset = 15
var pages []int
pageLimit := (float64(collection.TotalItems) / float64(offset))
@@ -83,13 +53,46 @@ func OutboxGet(ctx *fiber.Ctx) error {
pages = append(pages, int(i))
}
- returnData.Pages = pages
- returnData.TotalPage = len(returnData.Pages) - 1
+ var data PageData
+ data.Board.Name = actor.Name
+ data.Board.PrefName = actor.PreferredUsername
+ data.Board.Summary = actor.Summary
+ data.Board.InReplyTo = ""
+ data.Board.To = actor.Outbox
+ data.Board.Actor = actor
+ data.Board.ModCred, _ = getPassword(ctx)
+ data.Board.Domain = config.Domain
+ data.Board.Restricted = actor.Restricted
+ data.CurrentPage = page
+ data.ReturnTo = "feed"
+
+ data.Board.Post.Actor = actor.Id
+
+ capt, err := db.GetRandomCaptcha()
+ if err != nil {
+ return err
+ }
+ data.Board.Captcha = config.Domain + "/" + capt
+ data.Board.CaptchaCode = util.GetCaptchaCode(data.Board.Captcha)
+
+ data.Title = "/" + actor.Name + "/ - " + actor.PreferredUsername
+
+ data.Key = config.Key
+
+ data.Boards = db.Boards
+ data.Posts = collection.OrderedItems
+
+ data.Pages = pages
+ data.TotalPage = len(data.Pages) - 1
+
+ data.Meta.Description = data.Board.Summary
+ data.Meta.Url = data.Board.Actor.Id
+ data.Meta.Title = data.Title
- returnData.Themes = &config.Themes
- returnData.ThemeCookie = getThemeCookie(ctx)
+ data.Themes = &config.Themes
+ data.ThemeCookie = getThemeCookie(ctx)
return ctx.Render("nposts", fiber.Map{
- "page": returnData,
+ "page": data,
}, "layouts/main")
}
diff --git a/routes/post.go b/routes/post.go
index e074f67..8902f62 100644
--- a/routes/post.go
+++ b/routes/post.go
@@ -1,13 +1,13 @@
package routes
import (
- "fmt"
+ "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"
- "regexp"
)
func PostGet(ctx *fiber.Ctx) error {
@@ -20,34 +20,7 @@ func PostGet(ctx *fiber.Ctx) error {
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
+ var data PageData
re := regexp.MustCompile("f(\\w|[!@#$%^&*<>])+-(\\w|[!@#$%^&*<>])+")
@@ -65,15 +38,15 @@ func PostGet(ctx *fiber.Ctx) error {
}
if len(followCollection.OrderedItems) > 0 {
- returnData.Board.InReplyTo = followCollection.OrderedItems[0].Id
- returnData.Posts = append(returnData.Posts, followCollection.OrderedItems[0])
+ data.Board.InReplyTo = followCollection.OrderedItems[0].Id
+ data.Posts = append(data.Posts, followCollection.OrderedItems[0])
- actor, err := webfinger.FingerActor(returnData.Board.InReplyTo)
+ actor, err := webfinger.FingerActor(data.Board.InReplyTo)
if err != nil {
return err
}
- returnData.Board.Post.Actor = actor.Id
+ data.Board.Post.Actor = actor.Id
}
} else {
collection, err := db.GetObjectByIDFromDB(inReplyTo)
@@ -82,24 +55,58 @@ func PostGet(ctx *fiber.Ctx) error {
}
if collection.Actor != nil {
- returnData.Board.Post.Actor = collection.Actor.Id
- returnData.Board.InReplyTo = inReplyTo
+ data.Board.Post.Actor = collection.Actor.Id
+ data.Board.InReplyTo = inReplyTo
if len(collection.OrderedItems) > 0 {
- returnData.Posts = append(returnData.Posts, collection.OrderedItems[0])
+ data.Posts = append(data.Posts, collection.OrderedItems[0])
}
}
}
- if len(returnData.Posts) > 0 {
- returnData.PostId = util.ShortURL(returnData.Board.To, returnData.Posts[0].Id)
+ if len(data.Posts) > 0 {
+ data.PostId = util.ShortURL(data.Board.To, data.Posts[0].Id)
}
- returnData.Themes = &config.Themes
- returnData.ThemeCookie = getThemeCookie(ctx)
+ data.Board.Name = actor.Name
+ data.Board.PrefName = actor.PreferredUsername
+ data.Board.To = actor.Outbox
+ data.Board.Actor = actor
+ data.Board.Summary = actor.Summary
+ data.Board.ModCred, _ = getPassword(ctx)
+ data.Board.Domain = config.Domain
+ data.Board.Restricted = actor.Restricted
+ data.ReturnTo = "feed"
+
+ capt, err := db.GetRandomCaptcha()
+ if err != nil {
+ return err
+ }
+ data.Board.Captcha = config.Domain + "/" + capt
+ data.Board.CaptchaCode = util.GetCaptchaCode(data.Board.Captcha)
+
+ data.Instance, err = db.GetActorFromDB(config.Domain)
+ if err != nil {
+ return err
+ }
+
+ data.Key = config.Key
+ data.Boards = db.Boards
+
+ data.Title = "/" + data.Board.Name + "/ - " + data.PostId
+
+ if len(data.Posts) > 0 {
+ data.Meta.Description = data.Posts[0].Content
+ data.Meta.Url = data.Posts[0].Id
+ data.Meta.Title = data.Posts[0].Name
+ data.Meta.Preview = data.Posts[0].Preview.Href
+ }
+
+ data.Themes = &config.Themes
+ data.ThemeCookie = getThemeCookie(ctx)
return ctx.Render("npost", fiber.Map{
- "page": returnData,
+ "page": data,
}, "layouts/main")
}
@@ -112,8 +119,6 @@ func CatalogGet(ctx *fiber.Ctx) error {
collection, err := db.GetObjectFromDBCatalog(actor.Id)
- fmt.Println(err)
-
// TODO: implement this in template functions
// "showArchive": func() bool {
// col, err := db.GetActorCollectionDBTypeLimit(collection.Actor.Id, "Archive", 1)
@@ -128,22 +133,22 @@ func CatalogGet(ctx *fiber.Ctx) error {
// return false
//},
- var returnData PageData
- returnData.Board.Name = actor.Name
- returnData.Board.PrefName = actor.PreferredUsername
- returnData.Board.InReplyTo = ""
- 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.Key = config.Key
- returnData.ReturnTo = "catalog"
-
- returnData.Board.Post.Actor = actor.Id
-
- returnData.Instance, err = db.GetActorFromDB(config.Domain)
+ var data PageData
+ data.Board.Name = actor.Name
+ data.Board.PrefName = actor.PreferredUsername
+ data.Board.InReplyTo = ""
+ data.Board.To = actor.Outbox
+ data.Board.Actor = actor
+ data.Board.Summary = actor.Summary
+ data.Board.ModCred, _ = getPassword(ctx)
+ data.Board.Domain = config.Domain
+ data.Board.Restricted = actor.Restricted
+ data.Key = config.Key
+ data.ReturnTo = "catalog"
+
+ data.Board.Post.Actor = actor.Id
+
+ data.Instance, err = db.GetActorFromDB(config.Domain)
if err != nil {
return err
}
@@ -152,19 +157,23 @@ func CatalogGet(ctx *fiber.Ctx) error {
if err != nil {
return err
}
- returnData.Board.Captcha = config.Domain + "/" + capt
- returnData.Board.CaptchaCode = util.GetCaptchaCode(returnData.Board.Captcha)
- returnData.Title = "/" + actor.Name + "/ - " + actor.PreferredUsername
+ data.Board.Captcha = config.Domain + "/" + capt
+ data.Board.CaptchaCode = util.GetCaptchaCode(data.Board.Captcha)
+
+ data.Title = "/" + data.Board.Name + "/ - catalog"
- returnData.Boards = db.Boards
+ data.Boards = db.Boards
+ data.Posts = collection.OrderedItems
- returnData.Posts = collection.OrderedItems
+ data.Meta.Description = data.Board.Summary
+ data.Meta.Url = data.Board.Actor.Id
+ data.Meta.Title = data.Title
- returnData.Themes = &config.Themes
- returnData.ThemeCookie = getThemeCookie(ctx)
+ data.Themes = &config.Themes
+ data.ThemeCookie = getThemeCookie(ctx)
return ctx.Render("catalog", fiber.Map{
- "page": returnData,
+ "page": data,
}, "layouts/main")
}
diff --git a/routes/structs.go b/routes/structs.go
index c145a6d..8905e65 100644
--- a/routes/structs.go
+++ b/routes/structs.go
@@ -21,6 +21,7 @@ type PageData struct {
ReturnTo string
NewsItems []db.NewsItem
BoardRemainer []int
+ Meta Meta
Themes *[]string
ThemeCookie string
@@ -43,3 +44,10 @@ type AdminPage struct {
Themes *[]string
ThemeCookie string
}
+
+type Meta struct {
+ Title string
+ Description string
+ Url string
+ Preview string
+}