aboutsummaryrefslogtreecommitdiff
path: root/routes
diff options
context:
space:
mode:
authorFChannel <>2022-04-30 11:00:55 -0700
committerFChannel <>2022-06-19 12:53:29 -0700
commit1892327cee2c3fa1d3bea729bd08eb63c2189a96 (patch)
tree7b846f7d9caf46fba6c9d15ff81b9d89dcca9476 /routes
parent5b52d269faa2ce2014d0feba603a2122361cf4eb (diff)
restructured code base to prevent circular dependicies
Diffstat (limited to 'routes')
-rw-r--r--routes/admin.go5
-rw-r--r--routes/archive.go5
-rw-r--r--routes/index.go10
-rw-r--r--routes/news.go10
-rw-r--r--routes/outbox.go10
-rw-r--r--routes/post.go21
-rw-r--r--routes/structs.go12
-rw-r--r--routes/util.go12
8 files changed, 47 insertions, 38 deletions
diff --git a/routes/admin.go b/routes/admin.go
index 528e40c..c714b06 100644
--- a/routes/admin.go
+++ b/routes/admin.go
@@ -3,6 +3,7 @@ package routes
import (
"github.com/FChannel0/FChannel-Server/config"
"github.com/FChannel0/FChannel-Server/db"
+ "github.com/FChannel0/FChannel-Server/post"
"github.com/FChannel0/FChannel-Server/webfinger"
"github.com/gofiber/fiber/v2"
)
@@ -49,11 +50,11 @@ func AdminIndex(ctx *fiber.Ctx) error {
adminData.Board.ModCred, _ = db.GetPasswordFromSession(ctx)
adminData.Title = actor.Name + " Admin page"
- adminData.Boards = db.Boards
+ adminData.Boards = webfinger.Boards
adminData.Board.Post.Actor = actor.Id
- adminData.PostBlacklist, _ = db.GetRegexBlacklistDB()
+ adminData.PostBlacklist, _ = post.GetRegexBlacklistDB()
adminData.Themes = &config.Themes
diff --git a/routes/archive.go b/routes/archive.go
index 87f3b8b..f3b4487 100644
--- a/routes/archive.go
+++ b/routes/archive.go
@@ -5,6 +5,7 @@ import (
"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"
)
@@ -29,7 +30,7 @@ func ArchiveGet(ctx *fiber.Ctx) error {
returnData.Board.Post.Actor = actor.Id
var err error
- returnData.Instance, err = db.GetActorFromDB(config.Domain)
+ returnData.Instance, err = activitypub.GetActorFromDB(config.Domain)
capt, err := db.GetRandomCaptcha()
if err != nil {
@@ -40,7 +41,7 @@ func ArchiveGet(ctx *fiber.Ctx) error {
returnData.Title = "/" + actor.Name + "/ - " + actor.PreferredUsername
- returnData.Boards = db.Boards
+ returnData.Boards = webfinger.Boards
returnData.Posts = collection.OrderedItems
diff --git a/routes/index.go b/routes/index.go
index 23b3f39..015ad0c 100644
--- a/routes/index.go
+++ b/routes/index.go
@@ -1,22 +1,22 @@
package routes
import (
+ "github.com/FChannel0/FChannel-Server/activitypub"
"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 Index(ctx *fiber.Ctx) error {
- actor, err := db.GetActorFromDB(config.Domain)
+ actor, err := activitypub.GetActorFromDB(config.Domain)
if err != nil {
return err
}
// this is a activitpub json request return json instead of html page
- if util.AcceptActivity(ctx.Get("Accept")) {
- db.GetActorInfo(ctx, actor.Id)
+ if activitypub.AcceptActivity(ctx.Get("Accept")) {
+ activitypub.GetActorInfo(ctx, actor.Id)
return nil
}
@@ -38,7 +38,7 @@ func Index(ctx *fiber.Ctx) error {
data.Title = "Welcome to " + actor.PreferredUsername
data.PreferredUsername = actor.PreferredUsername
- data.Boards = db.Boards
+ data.Boards = webfinger.Boards
data.Board.Name = ""
data.Key = config.Key
data.Board.Domain = config.Domain
diff --git a/routes/news.go b/routes/news.go
index 98d0019..2a8a0f9 100644
--- a/routes/news.go
+++ b/routes/news.go
@@ -1,8 +1,10 @@
package routes
import (
+ "github.com/FChannel0/FChannel-Server/activitypub"
"github.com/FChannel0/FChannel-Server/config"
"github.com/FChannel0/FChannel-Server/db"
+ "github.com/FChannel0/FChannel-Server/webfinger"
"github.com/gofiber/fiber/v2"
)
@@ -10,14 +12,14 @@ func NewsGet(ctx *fiber.Ctx) error {
// TODO
timestamp := 0
- actor, err := db.GetActorFromDB(config.Domain)
+ actor, err := activitypub.GetActorFromDB(config.Domain)
if err != nil {
return err
}
var data PageData
data.PreferredUsername = actor.PreferredUsername
- data.Boards = db.Boards
+ data.Boards = webfinger.Boards
data.Board.Name = ""
data.Key = config.Key
data.Board.Domain = config.Domain
@@ -41,7 +43,7 @@ func NewsGet(ctx *fiber.Ctx) error {
}
func AllNewsGet(ctx *fiber.Ctx) error {
- actor, err := db.GetActorFromDB(config.Domain)
+ actor, err := activitypub.GetActorFromDB(config.Domain)
if err != nil {
return err
}
@@ -49,7 +51,7 @@ func AllNewsGet(ctx *fiber.Ctx) error {
var data PageData
data.PreferredUsername = actor.PreferredUsername
data.Title = actor.PreferredUsername + " News"
- data.Boards = db.Boards
+ data.Boards = webfinger.Boards
data.Board.Name = ""
data.Key = config.Key
data.Board.Domain = config.Domain
diff --git a/routes/outbox.go b/routes/outbox.go
index 4b874df..8049bd5 100644
--- a/routes/outbox.go
+++ b/routes/outbox.go
@@ -3,9 +3,11 @@ package routes
import (
"strconv"
+ "github.com/FChannel0/FChannel-Server/activitypub"
"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"
)
@@ -17,10 +19,10 @@ func Outbox(ctx *fiber.Ctx) error {
func OutboxGet(ctx *fiber.Ctx) error {
- actor := db.GetActorByName(ctx.Params("actor"))
+ actor := webfinger.GetActorByName(ctx.Params("actor"))
- if util.AcceptActivity(ctx.Get("Accept")) {
- db.GetActorInfo(ctx, actor.Id)
+ if activitypub.AcceptActivity(ctx.Get("Accept")) {
+ activitypub.GetActorInfo(ctx, actor.Id)
return nil
}
@@ -79,7 +81,7 @@ func OutboxGet(ctx *fiber.Ctx) error {
data.Key = config.Key
- data.Boards = db.Boards
+ data.Boards = webfinger.Boards
data.Posts = collection.OrderedItems
data.Pages = pages
diff --git a/routes/post.go b/routes/post.go
index 8902f62..016e533 100644
--- a/routes/post.go
+++ b/routes/post.go
@@ -3,6 +3,7 @@ package routes
import (
"regexp"
+ "github.com/FChannel0/FChannel-Server/activitypub"
"github.com/FChannel0/FChannel-Server/config"
"github.com/FChannel0/FChannel-Server/db"
"github.com/FChannel0/FChannel-Server/util"
@@ -11,7 +12,7 @@ import (
)
func PostGet(ctx *fiber.Ctx) error {
- actor, err := db.GetActorByNameFromDB(ctx.Params("actor"))
+ actor, err := activitypub.GetActorByNameFromDB(ctx.Params("actor"))
if err != nil {
return err
}
@@ -25,14 +26,14 @@ func PostGet(ctx *fiber.Ctx) error {
re := regexp.MustCompile("f(\\w|[!@#$%^&*<>])+-(\\w|[!@#$%^&*<>])+")
if re.MatchString(postId) { // if non local actor post
- name := util.GetActorFollowNameFromPath(postId)
+ name := activitypub.GetActorFollowNameFromPath(postId)
followActors, err := webfinger.GetActorsFollowFromName(actor, name)
if err != nil {
return err
}
- followCollection, err := db.GetActorsFollowPostFromId(followActors, postId)
+ followCollection, err := activitypub.GetActorsFollowPostFromId(followActors, postId)
if err != nil {
return err
}
@@ -49,7 +50,7 @@ func PostGet(ctx *fiber.Ctx) error {
data.Board.Post.Actor = actor.Id
}
} else {
- collection, err := db.GetObjectByIDFromDB(inReplyTo)
+ collection, err := activitypub.GetObjectByIDFromDB(inReplyTo)
if err != nil {
return err
}
@@ -85,13 +86,13 @@ func PostGet(ctx *fiber.Ctx) error {
data.Board.Captcha = config.Domain + "/" + capt
data.Board.CaptchaCode = util.GetCaptchaCode(data.Board.Captcha)
- data.Instance, err = db.GetActorFromDB(config.Domain)
+ data.Instance, err = activitypub.GetActorFromDB(config.Domain)
if err != nil {
return err
}
data.Key = config.Key
- data.Boards = db.Boards
+ data.Boards = webfinger.Boards
data.Title = "/" + data.Board.Name + "/ - " + data.PostId
@@ -112,12 +113,12 @@ func PostGet(ctx *fiber.Ctx) error {
func CatalogGet(ctx *fiber.Ctx) error {
actorName := ctx.Params("actor")
- actor, err := db.GetActorByNameFromDB(actorName)
+ actor, err := activitypub.GetActorByNameFromDB(actorName)
if err != nil {
return err
}
- collection, err := db.GetObjectFromDBCatalog(actor.Id)
+ collection, err := activitypub.GetObjectFromDBCatalog(actor.Id)
// TODO: implement this in template functions
// "showArchive": func() bool {
@@ -148,7 +149,7 @@ func CatalogGet(ctx *fiber.Ctx) error {
data.Board.Post.Actor = actor.Id
- data.Instance, err = db.GetActorFromDB(config.Domain)
+ data.Instance, err = activitypub.GetActorFromDB(config.Domain)
if err != nil {
return err
}
@@ -163,7 +164,7 @@ func CatalogGet(ctx *fiber.Ctx) error {
data.Title = "/" + data.Board.Name + "/ - catalog"
- data.Boards = db.Boards
+ data.Boards = webfinger.Boards
data.Posts = collection.OrderedItems
data.Meta.Description = data.Board.Summary
diff --git a/routes/structs.go b/routes/structs.go
index 8905e65..8cfb6ee 100644
--- a/routes/structs.go
+++ b/routes/structs.go
@@ -3,16 +3,18 @@ package routes
import (
"github.com/FChannel0/FChannel-Server/activitypub"
"github.com/FChannel0/FChannel-Server/db"
+ "github.com/FChannel0/FChannel-Server/post"
+ "github.com/FChannel0/FChannel-Server/webfinger"
)
type PageData struct {
Title string
PreferredUsername string
- Board db.Board
+ Board webfinger.Board
Pages []int
CurrentPage int
TotalPage int
- Boards []db.Board
+ Boards []webfinger.Board
Posts []activitypub.ObjectBase
Key string
PostId string
@@ -29,16 +31,16 @@ type PageData struct {
type AdminPage struct {
Title string
- Board db.Board
+ Board webfinger.Board
Key string
Actor string
- Boards []db.Board
+ Boards []webfinger.Board
Following []string
Followers []string
Reported []db.Report
Domain string
IsLocal bool
- PostBlacklist []db.PostBlacklist
+ PostBlacklist []post.PostBlacklist
AutoSubscribe bool
Themes *[]string
diff --git a/routes/util.go b/routes/util.go
index 3d03795..ef7d379 100644
--- a/routes/util.go
+++ b/routes/util.go
@@ -53,13 +53,13 @@ func wantToServePage(actorName string, page int) (activitypub.Collection, bool,
return collection, serve, ErrorPageLimit
}
- actor, err := db.GetActorByNameFromDB(actorName)
+ actor, err := activitypub.GetActorByNameFromDB(actorName)
if err != nil {
return collection, false, err
}
if actor.Id != "" {
- collection, err = db.GetObjectFromDBPage(actor.Id, page)
+ collection, err = activitypub.GetObjectFromDBPage(actor.Id, page)
if err != nil {
return collection, false, err
}
@@ -75,13 +75,13 @@ func wantToServeCatalog(actorName string) (activitypub.Collection, bool, error)
var collection activitypub.Collection
serve := false
- actor, err := db.GetActorByNameFromDB(actorName)
+ actor, err := activitypub.GetActorByNameFromDB(actorName)
if err != nil {
return collection, false, err
}
if actor.Id != "" {
- collection, err = db.GetObjectFromDBCatalog(actor.Id)
+ collection, err = activitypub.GetObjectFromDBCatalog(actor.Id)
if err != nil {
return collection, false, err
}
@@ -97,13 +97,13 @@ func wantToServeArchive(actorName string) (activitypub.Collection, bool, error)
var collection activitypub.Collection
serve := false
- actor, err := db.GetActorByNameFromDB(actorName)
+ actor, err := activitypub.GetActorByNameFromDB(actorName)
if err != nil {
return collection, false, err
}
if actor.Id != "" {
- collection, err = db.GetActorCollectionDBType(actor.Id, "Archive")
+ collection, err = activitypub.GetActorCollectionDBType(actor.Id, "Archive")
if err != nil {
return collection, false, err
}