aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFChannel <>2022-05-22 14:08:36 -0700
committerFChannel <>2022-06-19 12:53:29 -0700
commita66b676481d273508927e64a22e388dc302890ba (patch)
tree7c67b04dd8b39125526567ae6f08a39d0346d260
parent6a0f664b565716ad08301e7699d6c0393dbba977 (diff)
route organization
-rw-r--r--main.go24
-rw-r--r--route/routes/actor.go (renamed from routes/actor.go)305
-rw-r--r--route/routes/admin.go (renamed from routes/admin.go)5
-rw-r--r--route/routes/api.go (renamed from routes/api.go)0
-rw-r--r--route/routes/boardmgmt.go47
-rw-r--r--route/routes/main.go (renamed from routes/index.go)35
-rw-r--r--route/routes/news.go (renamed from routes/news.go)9
-rw-r--r--route/routes/webfinger.go (renamed from routes/webfinger.go)0
-rw-r--r--route/structs.go (renamed from routes/structs.go)2
-rw-r--r--route/util.go (renamed from routes/util.go)4
-rw-r--r--routes/404.go9
-rw-r--r--routes/archive.go53
-rw-r--r--routes/boardmgmt.go47
-rw-r--r--routes/follow.go17
-rw-r--r--routes/inbox.go9
-rw-r--r--routes/media.go7
-rw-r--r--routes/outbox.go106
-rw-r--r--routes/post.go189
18 files changed, 409 insertions, 459 deletions
diff --git a/main.go b/main.go
index cc167ed..0caa138 100644
--- a/main.go
+++ b/main.go
@@ -7,7 +7,8 @@ import (
"github.com/FChannel0/FChannel-Server/activitypub"
"github.com/FChannel0/FChannel-Server/config"
"github.com/FChannel0/FChannel-Server/db"
- "github.com/FChannel0/FChannel-Server/routes"
+ "github.com/FChannel0/FChannel-Server/route"
+ "github.com/FChannel0/FChannel-Server/route/routes"
"github.com/FChannel0/FChannel-Server/util"
"github.com/FChannel0/FChannel-Server/webfinger"
"github.com/gofiber/fiber/v2"
@@ -28,7 +29,7 @@ func main() {
template := html.New("./views", ".html")
template.Debug(true)
- routes.TemplateFunctions(template)
+ route.TemplateFunctions(template)
app := fiber.New(fiber.Config{
AppName: "FChannel",
@@ -68,6 +69,8 @@ func main() {
app.Get("/"+config.Key+"/newsdelete", routes.AdminNewsDelete)
app.All("/"+config.Key+"/:actor/follow", routes.AdminFollow)
app.Get("/"+config.Key+"/:actor", routes.AdminActorIndex)
+
+ // News routes
app.Get("/news", routes.NewsGet)
// Board managment
@@ -81,24 +84,25 @@ func main() {
app.Get("/poparchive", routes.BoardPopArchive)
app.Get("/autosubscribe", routes.BoardAutoSubscribe)
app.Get("/blacklist", routes.BoardBlacklist)
- app.Get("/report", routes.BoardBlacklist)
+ app.Get("/report", routes.BoardReport)
+
+ // Webfinger routes
app.Get("/.well-known/webfinger", routes.Webfinger)
+
+ // API routes
app.Get("/api/media", routes.Media)
- // Board actor
- app.Get("/:actor/catalog", routes.CatalogGet)
+ // Board actor routes
+ app.Get("/:actor/catalog", routes.ActorCatalogGet)
app.Post("/:actor/inbox", routes.ActorInbox)
app.All("/:actor/outbox", routes.ActorOutbox)
app.Get("/:actor/following", routes.ActorFollowing)
app.All("/:actor/followers", routes.ActorFollowers)
app.Get("/:actor/reported", routes.ActorReported)
app.Get("/:actor/archive", routes.ActorArchive)
- app.Get("/:actor", routes.OutboxGet)
+ app.Get("/:actor", routes.ActorOutboxGet)
app.Post("/:actor", routes.ActorPost)
- app.Get("/:actor/:post", routes.PostGet)
-
- //404 handler
- app.Use(routes.NotFound)
+ app.Get("/:actor/:post", routes.ActorPostGet)
db.PrintAdminAuth()
diff --git a/routes/actor.go b/route/routes/actor.go
index 4f848f1..e27133b 100644
--- a/routes/actor.go
+++ b/route/routes/actor.go
@@ -7,10 +7,13 @@ import (
"io/ioutil"
"mime/multipart"
"net/http"
+ "regexp"
+ "strconv"
"github.com/FChannel0/FChannel-Server/activitypub"
"github.com/FChannel0/FChannel-Server/config"
"github.com/FChannel0/FChannel-Server/post"
+ "github.com/FChannel0/FChannel-Server/route"
"github.com/FChannel0/FChannel-Server/util"
"github.com/FChannel0/FChannel-Server/webfinger"
"github.com/gofiber/fiber/v2"
@@ -196,7 +199,7 @@ func ActorOutbox(ctx *fiber.Ctx) error {
return nil
}
- return ParseOutboxRequest(ctx, actor)
+ return route.ParseOutboxRequest(ctx, actor)
}
func ActorFollowing(ctx *fiber.Ctx) error {
@@ -375,3 +378,303 @@ func ActorPost(ctx *fiber.Ctx) error {
return ctx.Redirect(config.Domain+"/"+ctx.FormValue("boardName"), 301)
}
+
+func ActorPostGet(ctx *fiber.Ctx) error {
+
+ actor, err := activitypub.GetActorByNameFromDB(ctx.Params("actor"))
+ if err != nil {
+ return nil
+ }
+
+ // this is a activitpub json request return json instead of html page
+ if activitypub.AcceptActivity(ctx.Get("Accept")) {
+ route.GetActorPost(ctx, ctx.Path())
+ return nil
+ }
+
+ re := regexp.MustCompile("\\w+$")
+ postId := re.FindString(ctx.Path())
+
+ inReplyTo := actor.Id + "/" + postId
+
+ var data route.PageData
+
+ re = regexp.MustCompile("f(\\w|[!@#$%^&*<>])+-(\\w|[!@#$%^&*<>])+")
+
+ if re.MatchString(ctx.Path()) { // if non local actor post
+ name := activitypub.GetActorFollowNameFromPath(ctx.Path())
+
+ followActors, err := actor.GetFollowFromName(name)
+ if err != nil {
+ return util.MakeError(err, "PostGet")
+ }
+
+ followCollection, err := activitypub.GetActorsFollowPostFromId(followActors, postId)
+ if err != nil {
+ return util.MakeError(err, "PostGet")
+ }
+
+ if len(followCollection.OrderedItems) > 0 {
+ data.Board.InReplyTo = followCollection.OrderedItems[0].Id
+ data.Posts = append(data.Posts, followCollection.OrderedItems[0])
+
+ actor, err := activitypub.FingerActor(data.Board.InReplyTo)
+ if err != nil {
+ return util.MakeError(err, "PostGet")
+ }
+
+ data.Board.Post.Actor = actor.Id
+ }
+ } else {
+ obj := activitypub.ObjectBase{Id: inReplyTo}
+ collection, err := obj.GetCollectionFromPath()
+ if err != nil {
+ return util.MakeError(err, "PostGet")
+ }
+
+ if collection.Actor.Id != "" {
+ data.Board.Post.Actor = collection.Actor.Id
+ data.Board.InReplyTo = inReplyTo
+ }
+
+ if len(collection.OrderedItems) > 0 {
+ data.Posts = append(data.Posts, collection.OrderedItems[0])
+ }
+ }
+
+ if len(data.Posts) > 0 {
+ data.PostId = util.ShortURL(data.Board.To, data.Posts[0].Id)
+ }
+
+ 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, _ = util.GetPasswordFromSession(ctx)
+ data.Board.Domain = config.Domain
+ data.Board.Restricted = actor.Restricted
+ data.ReturnTo = "feed"
+
+ capt, err := util.GetRandomCaptcha()
+ if err != nil {
+ return util.MakeError(err, "PostGet")
+ }
+ data.Board.Captcha = config.Domain + "/" + capt
+ data.Board.CaptchaCode = post.GetCaptchaCode(data.Board.Captcha)
+
+ data.Instance, err = activitypub.GetActorFromDB(config.Domain)
+ if err != nil {
+ return util.MakeError(err, "PostGet")
+ }
+
+ data.Key = config.Key
+ data.Boards = webfinger.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 = route.GetThemeCookie(ctx)
+
+ return ctx.Render("npost", fiber.Map{
+ "page": data,
+ }, "layouts/main")
+}
+
+func ActorCatalogGet(ctx *fiber.Ctx) error {
+ actorName := ctx.Params("actor")
+ actor, err := activitypub.GetActorByNameFromDB(actorName)
+ if err != nil {
+ return util.MakeError(err, "CatalogGet")
+ }
+
+ collection, err := actor.GetCatalogCollection()
+
+ // TODO: implement this in template functions
+ // "showArchive": func() bool {
+ // col, err := db.GetActorCollectionDBTypeLimit(collection.Actor.Id, "Archive", 1)
+ // if err != nil {
+ // // TODO: figure out what to do here
+ // panic(err)
+ // }
+ //
+ // if len(col.OrderedItems) > 0 {
+ // return true
+ // }
+ // return false
+ //},
+
+ var data route.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, _ = util.GetPasswordFromSession(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 = activitypub.GetActorFromDB(config.Domain)
+ if err != nil {
+ return util.MakeError(err, "CatalogGet")
+ }
+
+ capt, err := util.GetRandomCaptcha()
+ if err != nil {
+ return util.MakeError(err, "CatalogGet")
+ }
+
+ data.Board.Captcha = config.Domain + "/" + capt
+ data.Board.CaptchaCode = post.GetCaptchaCode(data.Board.Captcha)
+
+ data.Title = "/" + data.Board.Name + "/ - catalog"
+
+ data.Boards = webfinger.Boards
+ data.Posts = collection.OrderedItems
+
+ data.Meta.Description = data.Board.Summary
+ data.Meta.Url = data.Board.Actor.Id
+ data.Meta.Title = data.Title
+
+ data.Themes = &config.Themes
+ data.ThemeCookie = route.GetThemeCookie(ctx)
+
+ return ctx.Render("catalog", fiber.Map{
+ "page": data,
+ }, "layouts/main")
+}
+
+func ActorOutboxGet(ctx *fiber.Ctx) error {
+ actor, err := activitypub.GetActorByNameFromDB(ctx.Params("actor"))
+
+ if err != nil {
+ return nil
+ }
+
+ if activitypub.AcceptActivity(ctx.Get("Accept")) {
+ actor.GetInfoResp(ctx)
+ return nil
+ }
+
+ var page int
+ if postNum := ctx.Query("page"); postNum != "" {
+ if page, err = strconv.Atoi(postNum); err != nil {
+ return util.MakeError(err, "OutboxGet")
+ }
+ }
+
+ collection, err := actor.WantToServePage(page)
+ if err != nil {
+ return util.MakeError(err, "OutboxGet")
+ }
+
+ var offset = 15
+ var pages []int
+ pageLimit := (float64(collection.TotalItems) / float64(offset))
+
+ if pageLimit > 11 {
+ pageLimit = 11
+ }
+
+ for i := 0.0; i < pageLimit; i++ {
+ pages = append(pages, int(i))
+ }
+
+ var data route.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, _ = util.GetPasswordFromSession(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 := util.GetRandomCaptcha()
+ if err != nil {
+ return util.MakeError(err, "OutboxGet")
+ }
+ data.Board.Captcha = config.Domain + "/" + capt
+ data.Board.CaptchaCode = post.GetCaptchaCode(data.Board.Captcha)
+
+ data.Title = "/" + actor.Name + "/ - " + actor.PreferredUsername
+
+ data.Key = config.Key
+
+ data.Boards = webfinger.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
+
+ data.Themes = &config.Themes
+ data.ThemeCookie = route.GetThemeCookie(ctx)
+
+ return ctx.Render("nposts", fiber.Map{
+ "page": data,
+ }, "layouts/main")
+}
+
+func ActorArchiveGet(ctx *fiber.Ctx) error {
+ collection := ctx.Locals("collection").(activitypub.Collection)
+ actor := collection.Actor
+
+ var returnData route.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, _ = util.GetPasswordFromSession(ctx)
+ returnData.Board.Domain = config.Domain
+ returnData.Board.Restricted = actor.Restricted
+ returnData.Key = config.Key
+ returnData.ReturnTo = "archive"
+
+ returnData.Board.Post.Actor = actor.Id
+
+ var err error
+ returnData.Instance, err = activitypub.GetActorFromDB(config.Domain)
+
+ capt, err := util.GetRandomCaptcha()
+ if err != nil {
+ return util.MakeError(err, "ArchiveGet")
+ }
+ returnData.Board.Captcha = config.Domain + "/" + capt
+ returnData.Board.CaptchaCode = post.GetCaptchaCode(returnData.Board.Captcha)
+
+ returnData.Title = "/" + actor.Name + "/ - " + actor.PreferredUsername
+
+ returnData.Boards = webfinger.Boards
+
+ returnData.Posts = collection.OrderedItems
+
+ returnData.Themes = &config.Themes
+ returnData.ThemeCookie = route.GetThemeCookie(ctx)
+
+ return ctx.Render("archive", fiber.Map{
+ "page": returnData,
+ }, "layouts/main")
+}
diff --git a/routes/admin.go b/route/routes/admin.go
index d837a2f..86e12c6 100644
--- a/routes/admin.go
+++ b/route/routes/admin.go
@@ -10,6 +10,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/route"
"github.com/FChannel0/FChannel-Server/util"
"github.com/FChannel0/FChannel-Server/webfinger"
"github.com/gofiber/fiber/v2"
@@ -114,7 +115,7 @@ func AdminIndex(ctx *fiber.Ctx) error {
followers = append(followers, e.Id)
}
- var adminData AdminPage
+ var adminData route.AdminPage
adminData.Following = following
adminData.Followers = followers
adminData.Actor = actor.Id
@@ -258,7 +259,7 @@ func AdminActorIndex(ctx *fiber.Ctx) error {
reports = append(reports, r)
}
- var data AdminPage
+ var data route.AdminPage
data.Following = following
data.Followers = followers
data.Reported = reports
diff --git a/routes/api.go b/route/routes/api.go
index 080d88d..080d88d 100644
--- a/routes/api.go
+++ b/route/routes/api.go
diff --git a/route/routes/boardmgmt.go b/route/routes/boardmgmt.go
new file mode 100644
index 0000000..15b2686
--- /dev/null
+++ b/route/routes/boardmgmt.go
@@ -0,0 +1,47 @@
+package routes
+
+import "github.com/gofiber/fiber/v2"
+
+func BoardBanMedia(ctx *fiber.Ctx) error {
+ return ctx.SendString("board ban media")
+}
+
+func BoardDelete(ctx *fiber.Ctx) error {
+ return ctx.SendString("board delete")
+}
+
+func BoardDeleteAttach(ctx *fiber.Ctx) error {
+ return ctx.SendString("board delete attach")
+}
+
+func BoardMarkSensitive(ctx *fiber.Ctx) error {
+ return ctx.SendString("board mark sensitive")
+}
+
+func BoardRemove(ctx *fiber.Ctx) error {
+ return ctx.SendString("board remove")
+}
+
+func BoardRemoveAttach(ctx *fiber.Ctx) error {
+ return ctx.SendString("board remove attach")
+}
+
+func BoardAddToIndex(ctx *fiber.Ctx) error {
+ return ctx.SendString("board add to index")
+}
+
+func BoardPopArchive(ctx *fiber.Ctx) error {
+ return ctx.SendString("board pop archive")
+}
+
+func BoardAutoSubscribe(ctx *fiber.Ctx) error {
+ return ctx.SendString("board auto subscribe")
+}
+
+func BoardBlacklist(ctx *fiber.Ctx) error {
+ return ctx.SendString("board blacklist")
+}
+
+func BoardReport(ctx *fiber.Ctx) error {
+ return ctx.SendString("board report")
+}
diff --git a/routes/index.go b/route/routes/main.go
index 68fcfd0..99dad31 100644
--- a/routes/index.go
+++ b/route/routes/main.go
@@ -4,6 +4,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/route"
"github.com/FChannel0/FChannel-Server/util"
"github.com/FChannel0/FChannel-Server/webfinger"
"github.com/gofiber/fiber/v2"
@@ -21,7 +22,7 @@ func Index(ctx *fiber.Ctx) error {
return nil
}
- var data PageData
+ var data route.PageData
reqActivity := activitypub.Activity{Id: "https://fchan.xyz/followers"}
col, err := reqActivity.GetCollection()
@@ -61,9 +62,39 @@ func Index(ctx *fiber.Ctx) error {
data.Meta.Title = data.Title
data.Themes = &config.Themes
- data.ThemeCookie = getThemeCookie(ctx)
+ data.ThemeCookie = route.GetThemeCookie(ctx)
return ctx.Render("index", fiber.Map{
"page": data,
}, "layouts/main")
}
+
+func Inbox(ctx *fiber.Ctx) error {
+ // TODO main actor Inbox route
+ return ctx.SendString("main inbox")
+}
+
+func Outbox(ctx *fiber.Ctx) error {
+ actor, err := webfinger.GetActorFromPath(ctx.Path(), "/")
+
+ if err != nil {
+ return util.MakeError(err, "Outbox")
+ }
+
+ if activitypub.AcceptActivity(ctx.Get("Accept")) {
+ actor.GetOutbox(ctx)
+ return nil
+ }
+
+ return route.ParseOutboxRequest(ctx, actor)
+}
+
+func Following(ctx *fiber.Ctx) error {
+ actor, _ := activitypub.GetActorFromDB(config.Domain)
+ return actor.GetFollowingResp(ctx)
+}
+
+func Followers(ctx *fiber.Ctx) error {
+ actor, _ := activitypub.GetActorFromDB(config.Domain)
+ return actor.GetFollowersResp(ctx)
+}
diff --git a/routes/news.go b/route/routes/news.go
index c091605..0d226a5 100644
--- a/routes/news.go
+++ b/route/routes/news.go
@@ -4,6 +4,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/route"
"github.com/FChannel0/FChannel-Server/util"
"github.com/FChannel0/FChannel-Server/webfinger"
"github.com/gofiber/fiber/v2"
@@ -17,7 +18,7 @@ func NewsGet(ctx *fiber.Ctx) error {
return util.MakeError(err, "NewsGet")
}
- var data PageData
+ var data route.PageData
data.PreferredUsername = actor.PreferredUsername
data.Boards = webfinger.Boards
data.Board.Name = ""
@@ -37,7 +38,7 @@ func NewsGet(ctx *fiber.Ctx) error {
data.Title = actor.PreferredUsername + ": " + data.NewsItems[0].Title
data.Themes = &config.Themes
- data.ThemeCookie = getThemeCookie(ctx)
+ data.ThemeCookie = route.GetThemeCookie(ctx)
return ctx.Render("news", fiber.Map{"page": data}, "layouts/main")
}
@@ -48,7 +49,7 @@ func AllNewsGet(ctx *fiber.Ctx) error {
return util.MakeError(err, "AllNewsGet")
}
- var data PageData
+ var data route.PageData
data.PreferredUsername = actor.PreferredUsername
data.Title = actor.PreferredUsername + " News"
data.Boards = webfinger.Boards
@@ -66,7 +67,7 @@ func AllNewsGet(ctx *fiber.Ctx) error {
}
data.Themes = &config.Themes
- data.ThemeCookie = getThemeCookie(ctx)
+ data.ThemeCookie = route.GetThemeCookie(ctx)
return ctx.Render("anews", fiber.Map{"page": data}, "layouts/main")
}
diff --git a/routes/webfinger.go b/route/routes/webfinger.go
index 3d5fa63..3d5fa63 100644
--- a/routes/webfinger.go
+++ b/route/routes/webfinger.go
diff --git a/routes/structs.go b/route/structs.go
index 1c85676..7b1c2b8 100644
--- a/routes/structs.go
+++ b/route/structs.go
@@ -1,4 +1,4 @@
-package routes
+package route
import (
"github.com/FChannel0/FChannel-Server/activitypub"
diff --git a/routes/util.go b/route/util.go
index ed5dfb7..5bd15d6 100644
--- a/routes/util.go
+++ b/route/util.go
@@ -1,4 +1,4 @@
-package routes
+package route
import (
"encoding/json"
@@ -18,7 +18,7 @@ import (
"github.com/gofiber/template/html"
)
-func getThemeCookie(c *fiber.Ctx) string {
+func GetThemeCookie(c *fiber.Ctx) string {
cookie := c.Cookies("theme")
if cookie != "" {
cookies := strings.SplitN(cookie, "=", 2)
diff --git a/routes/404.go b/routes/404.go
deleted file mode 100644
index 94b96e8..0000000
--- a/routes/404.go
+++ /dev/null
@@ -1,9 +0,0 @@
-package routes
-
-import (
- "github.com/gofiber/fiber/v2"
-)
-
-func NotFound(c *fiber.Ctx) error {
- return c.Status(404).Render("404", fiber.Map{}, "layouts/main")
-}
diff --git a/routes/archive.go b/routes/archive.go
deleted file mode 100644
index c4950b4..0000000
--- a/routes/archive.go
+++ /dev/null
@@ -1,53 +0,0 @@
-package routes
-
-import (
- "github.com/FChannel0/FChannel-Server/activitypub"
- "github.com/FChannel0/FChannel-Server/config"
- "github.com/FChannel0/FChannel-Server/post"
- "github.com/FChannel0/FChannel-Server/util"
- "github.com/FChannel0/FChannel-Server/webfinger"
- "github.com/gofiber/fiber/v2"
-)
-
-func ArchiveGet(ctx *fiber.Ctx) error {
- collection := ctx.Locals("collection").(activitypub.Collection)
- actor := collection.Actor
-
- 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, _ = util.GetPasswordFromSession(ctx)
- returnData.Board.Domain = config.Domain
- returnData.Board.Restricted = actor.Restricted
- returnData.Key = config.Key
- returnData.ReturnTo = "archive"
-
- returnData.Board.Post.Actor = actor.Id
-
- var err error
- returnData.Instance, err = activitypub.GetActorFromDB(config.Domain)
-
- capt, err := util.GetRandomCaptcha()
- if err != nil {
- return util.MakeError(err, "ArchiveGet")
- }
- returnData.Board.Captcha = config.Domain + "/" + capt
- returnData.Board.CaptchaCode = post.GetCaptchaCode(returnData.Board.Captcha)
-
- returnData.Title = "/" + actor.Name + "/ - " + actor.PreferredUsername
-
- returnData.Boards = webfinger.Boards
-
- returnData.Posts = collection.OrderedItems
-
- returnData.Themes = &config.Themes
- returnData.ThemeCookie = getThemeCookie(ctx)
-
- return ctx.Render("archive", fiber.Map{
- "page": returnData,
- }, "layouts/main")
-}
diff --git a/routes/boardmgmt.go b/routes/boardmgmt.go
deleted file mode 100644
index 12e133d..0000000
--- a/routes/boardmgmt.go
+++ /dev/null
@@ -1,47 +0,0 @@
-package routes
-
-import "github.com/gofiber/fiber/v2"
-
-func BoardBanMedia(c *fiber.Ctx) error {
- return c.SendString("board ban media")
-}
-
-func BoardDelete(c *fiber.Ctx) error {
- return c.SendString("board delete")
-}
-
-func BoardDeleteAttach(c *fiber.Ctx) error {
- return c.SendString("board delete attach")
-}
-
-func BoardMarkSensitive(c *fiber.Ctx) error {
- return c.SendString("board mark sensitive")
-}
-
-func BoardRemove(c *fiber.Ctx) error {
- return c.SendString("board remove")
-}
-
-func BoardRemoveAttach(c *fiber.Ctx) error {
- return c.SendString("board remove attach")
-}
-
-func BoardAddToIndex(c *fiber.Ctx) error {
- return c.SendString("board add to index")
-}
-
-func BoardPopArchive(c *fiber.Ctx) error {
- return c.SendString("board pop archive")
-}
-
-func BoardAutoSubscribe(c *fiber.Ctx) error {
- return c.SendString("board auto subscribe")
-}
-
-func BoardBlacklist(c *fiber.Ctx) error {
- return c.SendString("board blacklist")
-}
-
-func BoardReport(c *fiber.Ctx) error {
- return c.SendString("board report")
-}
diff --git a/routes/follow.go b/routes/follow.go
deleted file mode 100644
index f61e405..0000000
--- a/routes/follow.go
+++ /dev/null
@@ -1,17 +0,0 @@
-package routes
-
-import (
- "github.com/FChannel0/FChannel-Server/activitypub"
- "github.com/FChannel0/FChannel-Server/config"
- "github.com/gofiber/fiber/v2"
-)
-
-func Following(ctx *fiber.Ctx) error {
- actor, _ := activitypub.GetActorFromDB(config.Domain)
- return actor.GetFollowingResp(ctx)
-}
-
-func Followers(ctx *fiber.Ctx) error {
- actor, _ := activitypub.GetActorFromDB(config.Domain)
- return actor.GetFollowersResp(ctx)
-}
diff --git a/routes/inbox.go b/routes/inbox.go
deleted file mode 100644
index 2f88329..0000000
--- a/routes/inbox.go
+++ /dev/null
@@ -1,9 +0,0 @@
-package routes
-
-import "github.com/gofiber/fiber/v2"
-
-func Inbox(c *fiber.Ctx) error {
- // STUB
-
- return c.SendString("main inbox")
-}
diff --git a/routes/media.go b/routes/media.go
deleted file mode 100644
index a4543c1..0000000
--- a/routes/media.go
+++ /dev/null
@@ -1,7 +0,0 @@
-package routes
-
-import "github.com/gofiber/fiber/v2"
-
-func ApiMedia(c *fiber.Ctx) error {
- return c.SendString("api media")
-}
diff --git a/routes/outbox.go b/routes/outbox.go
deleted file mode 100644
index 1d0d52e..0000000
--- a/routes/outbox.go
+++ /dev/null
@@ -1,106 +0,0 @@
-package routes
-
-import (
- "strconv"
-
- "github.com/FChannel0/FChannel-Server/activitypub"
- "github.com/FChannel0/FChannel-Server/config"
- "github.com/FChannel0/FChannel-Server/post"
- "github.com/FChannel0/FChannel-Server/util"
- "github.com/FChannel0/FChannel-Server/webfinger"
- "github.com/gofiber/fiber/v2"
-)
-
-func Outbox(ctx *fiber.Ctx) error {
- actor, err := webfinger.GetActorFromPath(ctx.Path(), "/")
- if err != nil {
- return util.MakeError(err, "Outbox")
- }
-
- if activitypub.AcceptActivity(ctx.Get("Accept")) {
- actor.GetOutbox(ctx)
- return nil
- }
-
- return ParseOutboxRequest(ctx, actor)
-}
-
-func OutboxGet(ctx *fiber.Ctx) error {
- actor, err := activitypub.GetActorByNameFromDB(ctx.Params("actor"))
-
- if err != nil {
- return nil
- }
-
- if activitypub.AcceptActivity(ctx.Get("Accept")) {
- actor.GetInfoResp(ctx)
- return nil
- }
-
- var page int
- if postNum := ctx.Query("page"); postNum != "" {
- if page, err = strconv.Atoi(postNum); err != nil {
- return util.MakeError(err, "OutboxGet")
- }
- }
-
- collection, err := actor.WantToServePage(page)
- if err != nil {
- return util.MakeError(err, "OutboxGet")
- }
-
- var offset = 15
- var pages []int
- pageLimit := (float64(collection.TotalItems) / float64(offset))
-
- if pageLimit > 11 {
- pageLimit = 11
- }
-
- for i := 0.0; i < pageLimit; i++ {
- pages = append(pages, int(i))
- }
-
- 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, _ = util.GetPasswordFromSession(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 := util.GetRandomCaptcha()
- if err != nil {
- return util.MakeError(err, "OutboxGet")
- }
- data.Board.Captcha = config.Domain + "/" + capt
- data.Board.CaptchaCode = post.GetCaptchaCode(data.Board.Captcha)
-
- data.Title = "/" + actor.Name + "/ - " + actor.PreferredUsername
-
- data.Key = config.Key
-
- data.Boards = webfinger.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
-
- data.Themes = &config.Themes
- data.ThemeCookie = getThemeCookie(ctx)
-
- return ctx.Render("nposts", fiber.Map{
- "page": data,
- }, "layouts/main")
-}
diff --git a/routes/post.go b/routes/post.go
deleted file mode 100644
index 4002be7..0000000
--- a/routes/post.go
+++ /dev/null
@@ -1,189 +0,0 @@
-package routes
-
-import (
- "regexp"
-
- "github.com/FChannel0/FChannel-Server/activitypub"
- "github.com/FChannel0/FChannel-Server/config"
- "github.com/FChannel0/FChannel-Server/post"
- "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 := activitypub.GetActorByNameFromDB(ctx.Params("actor"))
- if err != nil {
- return nil
- }
-
- // this is a activitpub json request return json instead of html page
- if activitypub.AcceptActivity(ctx.Get("Accept")) {
- GetActorPost(ctx, ctx.Path())
- return nil
- }
-
- re := regexp.MustCompile("\\w+$")
- postId := re.FindString(ctx.Path())
-
- inReplyTo := actor.Id + "/" + postId
-
- var data PageData
-
- re = regexp.MustCompile("f(\\w|[!@#$%^&*<>])+-(\\w|[!@#$%^&*<>])+")
-
- if re.MatchString(ctx.Path()) { // if non local actor post
- name := activitypub.GetActorFollowNameFromPath(ctx.Path())
-
- followActors, err := actor.GetFollowFromName(name)
- if err != nil {
- return util.MakeError(err, "PostGet")
- }
-
- followCollection, err := activitypub.GetActorsFollowPostFromId(followActors, postId)
- if err != nil {
- return util.MakeError(err, "PostGet")
- }
-
- if len(followCollection.OrderedItems) > 0 {
- data.Board.InReplyTo = followCollection.OrderedItems[0].Id
- data.Posts = append(data.Posts, followCollection.OrderedItems[0])
-
- actor, err := activitypub.FingerActor(data.Board.InReplyTo)
- if err != nil {
- return util.MakeError(err, "PostGet")
- }
-
- data.Board.Post.Actor = actor.Id
- }
- } else {
- obj := activitypub.ObjectBase{Id: inReplyTo}
- collection, err := obj.GetCollectionFromPath()
- if err != nil {
- return util.MakeError(err, "PostGet")
- }
-
- if collection.Actor.Id != "" {
- data.Board.Post.Actor = collection.Actor.Id
- data.Board.InReplyTo = inReplyTo
- }
-
- if len(collection.OrderedItems) > 0 {
- data.Posts = append(data.Posts, collection.OrderedItems[0])
- }
- }
-
- if len(data.Posts) > 0 {
- data.PostId = util.ShortURL(data.Board.To, data.Posts[0].Id)
- }
-
- 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, _ = util.GetPasswordFromSession(ctx)
- data.Board.Domain = config.Domain
- data.Board.Restricted = actor.Restricted
- data.ReturnTo = "feed"
-
- capt, err := util.GetRandomCaptcha()
- if err != nil {
- return util.MakeError(err, "PostGet")
- }
- data.Board.Captcha = config.Domain + "/" + capt
- data.Board.CaptchaCode = post.GetCaptchaCode(data.Board.Captcha)
-
- data.Instance, err = activitypub.GetActorFromDB(config.Domain)
- if err != nil {
- return util.MakeError(err, "PostGet")
- }
-
- data.Key = config.Key
- data.Boards = webfinger.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": data,
- }, "layouts/main")
-}
-
-func CatalogGet(ctx *fiber.Ctx) error {
- actorName := ctx.Params("actor")
- actor, err := activitypub.GetActorByNameFromDB(actorName)
- if err != nil {
- return util.MakeError(err, "CatalogGet")
- }
-
- collection, err := actor.GetCatalogCollection()
-
- // TODO: implement this in template functions
- // "showArchive": func() bool {
- // col, err := db.GetActorCollectionDBTypeLimit(collection.Actor.Id, "Archive", 1)
- // if err != nil {
- // // TODO: figure out what to do here
- // panic(err)
- // }
- //
- // if len(col.OrderedItems) > 0 {
- // return true
- // }
- // return false
- //},
-
- 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, _ = util.GetPasswordFromSession(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 = activitypub.GetActorFromDB(config.Domain)
- if err != nil {
- return util.MakeError(err, "CatalogGet")
- }
-
- capt, err := util.GetRandomCaptcha()
- if err != nil {
- return util.MakeError(err, "CatalogGet")
- }
-
- data.Board.Captcha = config.Domain + "/" + capt
- data.Board.CaptchaCode = post.GetCaptchaCode(data.Board.Captcha)
-
- data.Title = "/" + data.Board.Name + "/ - catalog"
-
- data.Boards = webfinger.Boards
- data.Posts = collection.OrderedItems
-
- data.Meta.Description = data.Board.Summary
- data.Meta.Url = data.Board.Actor.Id
- data.Meta.Title = data.Title
-
- data.Themes = &config.Themes
- data.ThemeCookie = getThemeCookie(ctx)
-
- return ctx.Render("catalog", fiber.Map{
- "page": data,
- }, "layouts/main")
-}