diff options
author | FChannel <> | 2022-05-07 15:11:35 -0700 |
---|---|---|
committer | FChannel <> | 2022-06-19 12:53:29 -0700 |
commit | 3c5eebf6275e6d202f8a7b7f027aabcda5c1f332 (patch) | |
tree | 5fa2d82f9375ac49be357f0f8b70db06d5c97305 /routes | |
parent | 39012c6b17073f6933a5ead8beed64df555f7348 (diff) |
more organizing structs to have object functions
need to fully test to be sure nothing broke with changes
Diffstat (limited to 'routes')
-rw-r--r-- | routes/actor.go | 10 | ||||
-rw-r--r-- | routes/admin.go | 2 | ||||
-rw-r--r-- | routes/archive.go | 2 | ||||
-rw-r--r-- | routes/post.go | 18 | ||||
-rw-r--r-- | routes/util.go | 12 |
5 files changed, 23 insertions, 21 deletions
diff --git a/routes/actor.go b/routes/actor.go index ea8656f..86a5fb9 100644 --- a/routes/actor.go +++ b/routes/actor.go @@ -43,7 +43,7 @@ func ActorInbox(ctx *fiber.Ctx) error { for _, e := range activity.To { if res, err := activitypub.IsActorLocal(e); err == nil && res { if res, err := activitypub.IsActorLocal(activity.Actor.Id); err == nil && res { - col, err := activitypub.GetCollectionFromID(activity.Object.Id) + col, err := activity.Object.GetCollection() if err != nil { return err } @@ -52,7 +52,7 @@ func ActorInbox(ctx *fiber.Ctx) error { break } - if _, err := activitypub.WriteObjectToCache(*activity.Object); err != nil { + if err := activity.Object.WriteCache(); err != nil { return err } @@ -84,15 +84,15 @@ func ActorInbox(ctx *fiber.Ctx) error { } if actor.Id != "" && actor.Id != config.Domain { - if activity.Object.Replies != nil { + if activity.Object.Replies.OrderedItems != nil { for _, k := range activity.Object.Replies.OrderedItems { - if err := activitypub.TombstoneObject(k.Id); err != nil { + if err := k.Tombstone(); err != nil { return err } } } - if err := activitypub.TombstoneObject(activity.Object.Id); err != nil { + if err := activity.Object.Tombstone(); err != nil { return err } if err := actor.UnArchiveLast(); err != nil { diff --git a/routes/admin.go b/routes/admin.go index ea27792..f8f55eb 100644 --- a/routes/admin.go +++ b/routes/admin.go @@ -318,7 +318,7 @@ func AdminActorIndex(ctx *fiber.Ctx) error { data.Themes = &config.Themes - data.RecentPosts = activitypub.GetRecentPostsDB(actor.Id) + data.RecentPosts, _ = actor.GetRecentPosts() if cookie := ctx.Cookies("theme"); cookie != "" { data.ThemeCookie = cookie diff --git a/routes/archive.go b/routes/archive.go index 746169f..c0f4ff6 100644 --- a/routes/archive.go +++ b/routes/archive.go @@ -19,7 +19,7 @@ func ArchiveGet(ctx *fiber.Ctx) error { returnData.Board.PrefName = actor.PreferredUsername returnData.Board.InReplyTo = "" returnData.Board.To = actor.Outbox - returnData.Board.Actor = *actor + returnData.Board.Actor = actor returnData.Board.Summary = actor.Summary returnData.Board.ModCred, _ = db.GetPasswordFromSession(ctx) returnData.Board.Domain = config.Domain diff --git a/routes/post.go b/routes/post.go index 1634346..ac722be 100644 --- a/routes/post.go +++ b/routes/post.go @@ -23,13 +23,14 @@ func PostGet(ctx *fiber.Ctx) error { return nil } - postId := ctx.Params("post") + re := regexp.MustCompile("\\w+$") + postId := re.FindString(ctx.Path()) inReplyTo := actor.Id + "/" + postId var data PageData - re := regexp.MustCompile("f(\\w|[!@#$%^&*<>])+-(\\w|[!@#$%^&*<>])+") + re = regexp.MustCompile("f(\\w|[!@#$%^&*<>])+-(\\w|[!@#$%^&*<>])+") if re.MatchString(ctx.Path()) { // if non local actor post name := activitypub.GetActorFollowNameFromPath(ctx.Path()) @@ -56,18 +57,19 @@ func PostGet(ctx *fiber.Ctx) error { data.Board.Post.Actor = actor.Id } } else { - collection, err := activitypub.GetObjectByIDFromDB(inReplyTo) + obj := activitypub.ObjectBase{Id: inReplyTo} + collection, err := obj.GetCollectionFromPath() if err != nil { return err } - if collection.Actor != nil { + 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(collection.OrderedItems) > 0 { + data.Posts = append(data.Posts, collection.OrderedItems[0]) } } @@ -124,7 +126,7 @@ func CatalogGet(ctx *fiber.Ctx) error { return err } - collection, err := activitypub.GetObjectFromDBCatalog(actor.Id) + collection, err := actor.GetCatalogCollection() // TODO: implement this in template functions // "showArchive": func() bool { diff --git a/routes/util.go b/routes/util.go index ee6d062..778f52b 100644 --- a/routes/util.go +++ b/routes/util.go @@ -45,12 +45,12 @@ func wantToServePage(actorName string, page int) (activitypub.Collection, bool, } if actor.Id != "" { - collection, err = activitypub.GetObjectFromDBPage(actor.Id, page) + collection, err = actor.GetCollectionPage(page) if err != nil { return collection, false, err } - collection.Actor = &actor + collection.Actor = actor return collection, true, nil } @@ -67,12 +67,12 @@ func wantToServeCatalog(actorName string) (activitypub.Collection, bool, error) } if actor.Id != "" { - collection, err = activitypub.GetObjectFromDBCatalog(actor.Id) + collection, err = actor.GetCatalogCollection() if err != nil { return collection, false, err } - collection.Actor = &actor + collection.Actor = actor return collection, true, nil } @@ -94,7 +94,7 @@ func wantToServeArchive(actorName string) (activitypub.Collection, bool, error) return collection, false, err } - collection.Actor = &actor + collection.Actor = actor return collection, true, nil } @@ -147,7 +147,7 @@ func ParseOutboxRequest(ctx *fiber.Ctx, actor activitypub.Actor) error { nObj.Actor = config.Domain + "/" + actor.Name - nObj, err = activitypub.WriteObjectToDB(nObj) + nObj, err = nObj.Write() if err != nil { return err } |