From 972223c992ca5aa5e5d93cff3b2ee4e30182025b Mon Sep 17 00:00:00 2001 From: KushBlazingJudah <59340248+KushBlazingJudah@users.noreply.github.com> Date: Sun, 7 Nov 2021 00:32:39 -0300 Subject: restructuring part 5 --- routes/util.go | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) (limited to 'routes/util.go') diff --git a/routes/util.go b/routes/util.go index a38e969..0a8dc9c 100644 --- a/routes/util.go +++ b/routes/util.go @@ -1,13 +1,17 @@ package routes import ( + "errors" "fmt" "strings" + "github.com/FChannel0/FChannel-Server/activitypub" "github.com/FChannel0/FChannel-Server/db" "github.com/gofiber/fiber/v2" ) +var ErrorPageLimit = errors.New("above page limit") + func getThemeCookie(c *fiber.Ctx) string { cookie := c.Cookies("theme") if cookie != "" { @@ -38,3 +42,74 @@ func getPassword(r *fiber.Ctx) (string, string) { return "", "" } + +func wantToServePage(actorName string, page int) (activitypub.Collection, bool, error) { + var collection activitypub.Collection + serve := false + + // TODO: don't hard code? + if page > 10 { + return collection, serve, ErrorPageLimit + } + + actor, err := db.GetActorByNameFromDB(actorName) + if err != nil { + return collection, false, err + } + + if actor.Id != "" { + collection, err = db.GetObjectFromDBPage(actor.Id, page) + if err != nil { + return collection, false, err + } + + collection.Actor = &actor + return collection, true, nil + } + + return collection, serve, nil +} + +func wantToServeCatalog(actorName string) (activitypub.Collection, bool, error) { + var collection activitypub.Collection + serve := false + + actor, err := db.GetActorByNameFromDB(actorName) + if err != nil { + return collection, false, err + } + + if actor.Id != "" { + collection, err = db.GetObjectFromDBCatalog(actor.Id) + if err != nil { + return collection, false, err + } + + collection.Actor = &actor + return collection, true, nil + } + + return collection, serve, nil +} + +func wantToServeArchive(actorName string) (activitypub.Collection, bool, error) { + var collection activitypub.Collection + serve := false + + actor, err := db.GetActorByNameFromDB(actorName) + if err != nil { + return collection, false, err + } + + if actor.Id != "" { + collection, err = db.GetActorCollectionDBType(actor.Id, "Archive") + if err != nil { + return collection, false, err + } + + collection.Actor = &actor + return collection, true, nil + } + + return collection, serve, nil +} -- cgit v1.2.3