diff options
author | FChannel <> | 2022-05-07 21:21:38 -0700 |
---|---|---|
committer | FChannel <> | 2022-06-19 12:53:29 -0700 |
commit | f7bf818d29393ceaccf4d2906557351fa6a4f49f (patch) | |
tree | 723e542c8cf0db1e7e64923718977138db77b58d /routes/util.go | |
parent | 3c5eebf6275e6d202f8a7b7f027aabcda5c1f332 (diff) |
added error func and general cleanup/organization
Diffstat (limited to 'routes/util.go')
-rw-r--r-- | routes/util.go | 41 |
1 files changed, 17 insertions, 24 deletions
diff --git a/routes/util.go b/routes/util.go index 778f52b..de0c6e0 100644 --- a/routes/util.go +++ b/routes/util.go @@ -1,7 +1,7 @@ package routes import ( - "errors" + "encoding/json" "fmt" "html/template" "regexp" @@ -18,8 +18,6 @@ import ( "github.com/gofiber/template/html" ) -var ErrorPageLimit = errors.New("above page limit") - func getThemeCookie(c *fiber.Ctx) string { cookie := c.Cookies("theme") if cookie != "" { @@ -30,22 +28,17 @@ func getThemeCookie(c *fiber.Ctx) string { return "default" } -func wantToServePage(actorName string, page int) (activitypub.Collection, bool, error) { +func wantToServeCatalog(actorName string) (activitypub.Collection, bool, error) { var collection activitypub.Collection serve := false - // TODO: don't hard code? - if page > 10 { - return collection, serve, ErrorPageLimit - } - actor, err := activitypub.GetActorByNameFromDB(actorName) if err != nil { return collection, false, err } if actor.Id != "" { - collection, err = actor.GetCollectionPage(page) + collection, err = actor.GetCatalogCollection() if err != nil { return collection, false, err } @@ -57,7 +50,7 @@ func wantToServePage(actorName string, page int) (activitypub.Collection, bool, return collection, serve, nil } -func wantToServeCatalog(actorName string) (activitypub.Collection, bool, error) { +func wantToServeArchive(actorName string) (activitypub.Collection, bool, error) { var collection activitypub.Collection serve := false @@ -67,7 +60,7 @@ func wantToServeCatalog(actorName string) (activitypub.Collection, bool, error) } if actor.Id != "" { - collection, err = actor.GetCatalogCollection() + collection, err = actor.GetCollectionType("Archive") if err != nil { return collection, false, err } @@ -79,26 +72,26 @@ func wantToServeCatalog(actorName string) (activitypub.Collection, bool, error) return collection, serve, nil } -func wantToServeArchive(actorName string) (activitypub.Collection, bool, error) { - var collection activitypub.Collection - serve := false +func GetActorPost(ctx *fiber.Ctx, path string) error { + obj := activitypub.ObjectBase{Id: config.Domain + "" + path} + collection, err := obj.GetCollectionFromPath() - actor, err := activitypub.GetActorByNameFromDB(actorName) if err != nil { - return collection, false, err + return err } - if actor.Id != "" { - collection, err = actor.GetCollectionType("Archive") + if len(collection.OrderedItems) > 0 { + enc, err := json.MarshalIndent(collection, "", "\t") if err != nil { - return collection, false, err + return err } - collection.Actor = actor - return collection, true, nil + ctx.Response().Header.Set("Content-Type", "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"") + _, err = ctx.Write(enc) + return err } - return collection, serve, nil + return nil } func ParseOutboxRequest(ctx *fiber.Ctx, actor activitypub.Actor) error { @@ -194,7 +187,7 @@ func ParseOutboxRequest(ctx *fiber.Ctx, actor activitypub.Actor) error { return err } - if res, err := activitypub.IsActivityLocal(activity); err == nil && res { + if res, err := activity.IsLocal(); err == nil && res { if res := db.VerifyHeaderSignature(ctx, *activity.Actor); err == nil && !res { ctx.Response().Header.Set("Status", "403") _, err = ctx.Write([]byte("")) |