From 390ac7e883795fc6a5b8b9a6fbcaa204e2099970 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 8 Mar 2025 22:56:36 +0800 Subject: [PATCH] :bug: Trying to fix some bugs --- pkg/internal/http/api/posts_api.go | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/pkg/internal/http/api/posts_api.go b/pkg/internal/http/api/posts_api.go index 967e2ad..bb2c3da 100644 --- a/pkg/internal/http/api/posts_api.go +++ b/pkg/internal/http/api/posts_api.go @@ -21,12 +21,16 @@ import ( ) func UniversalPostFilter(c *fiber.Ctx, tx *gorm.DB) (*gorm.DB, error) { - tx = services.FilterPostDraft(tx) - if user, authenticated := c.Locals("user").(authm.Account); authenticated { tx = services.FilterPostWithUserContext(c, tx, &user) + if c.QueryBool("noDraft", true) { + tx = services.FilterPostDraft(tx) + } else { + tx = services.FilterPostDraftWithAuthor(database.C, user.ID) + } } else { tx = services.FilterPostWithUserContext(c, tx, nil) + tx = services.FilterPostDraft(tx) } if c.QueryBool("noReply", true) { @@ -70,16 +74,8 @@ func getPost(c *fiber.Ctx) error { tx := database.C - if user, authenticated := c.Locals("user").(authm.Account); authenticated { - tx = services.FilterPostDraftWithAuthor(database.C, user.ID) - } else { - tx = services.FilterPostDraft(database.C) - } - - if user, authenticated := c.Locals("user").(authm.Account); authenticated { - tx = services.FilterPostWithUserContext(c, tx, &user) - } else { - tx = services.FilterPostWithUserContext(c, tx, nil) + if tx, err = UniversalPostFilter(c, tx); err != nil { + return err } if numericId, paramErr := strconv.Atoi(id); paramErr == nil {