aboutsummaryrefslogtreecommitdiff
path: root/routes/util.go
diff options
context:
space:
mode:
Diffstat (limited to 'routes/util.go')
-rw-r--r--routes/util.go41
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(""))