diff --git a/go.mod b/go.mod index d2b22aa..b16f812 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module git.solsynth.dev/hydrogen/interactive go 1.21.6 require ( - git.solsynth.dev/hydrogen/paperclip v0.0.0-20240517123600-145c5563a55e + git.solsynth.dev/hydrogen/paperclip v0.0.0-20240518085442-715238074040 git.solsynth.dev/hydrogen/passport v0.0.0-20240517123434-ebef35a619f5 github.com/go-playground/validator/v10 v10.17.0 github.com/gofiber/fiber/v2 v2.52.4 diff --git a/go.sum b/go.sum index 92b35d4..0cfbcca 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ git.solsynth.dev/hydrogen/paperclip v0.0.0-20240517123600-145c5563a55e h1:jQNErCjKl76zVO2+nkBvKJK5eEkOVhVXQh4FMm8G0Xc= git.solsynth.dev/hydrogen/paperclip v0.0.0-20240517123600-145c5563a55e/go.mod h1:uTNEtJcNdgt7DhOgsewPaLQQ5kTN9H+tGNRT2CshHGs= +git.solsynth.dev/hydrogen/paperclip v0.0.0-20240518085442-715238074040 h1:B/3gXFaxoLdD7icLu33OXrx166raEHtHdfhCFrPYgTE= +git.solsynth.dev/hydrogen/paperclip v0.0.0-20240518085442-715238074040/go.mod h1:uTNEtJcNdgt7DhOgsewPaLQQ5kTN9H+tGNRT2CshHGs= git.solsynth.dev/hydrogen/passport v0.0.0-20240517123434-ebef35a619f5 h1:iEnty5+OHZiIaa27/e9qXfj7lmlhUVe8Oog/BJmLsRM= git.solsynth.dev/hydrogen/passport v0.0.0-20240517123434-ebef35a619f5/go.mod h1:mEcDEKashAh3jvoGDbNLefK+HgsJaMj4xEc6vkLZ+Zc= github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M= diff --git a/pkg/models/posts.go b/pkg/models/posts.go index aa8bf8e..de463dd 100644 --- a/pkg/models/posts.go +++ b/pkg/models/posts.go @@ -36,7 +36,7 @@ type Post struct { Author Account `json:"author"` // Dynamic Calculated Values - ReplyCount int64 `json:"comment_count"` + ReplyCount int64 `json:"reply_count"` ReactionCount int64 `json:"reaction_count"` ReactionList map[string]int64 `json:"reaction_list" gorm:"-"` } diff --git a/pkg/server/posts_api.go b/pkg/server/posts_api.go index d39dfb6..91de44a 100644 --- a/pkg/server/posts_api.go +++ b/pkg/server/posts_api.go @@ -94,8 +94,8 @@ func createPost(c *fiber.Ctx) error { } for _, attachment := range data.Attachments { - if _, err := services.GetAttachmentByUUID(attachment); err != nil { - return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("attachment %s not found: %v", attachment, err)) + if services.CheckAttachmentByUUIDExists(attachment, "i.attachment") { + return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("attachment %s not found", attachment)) } } @@ -170,8 +170,8 @@ func editPost(c *fiber.Ctx) error { } for _, attachment := range data.Attachments { - if _, err := services.GetAttachmentByUUID(attachment); err != nil { - return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("attachment %s not found: %v", attachment, err)) + if services.CheckAttachmentByUUIDExists(attachment, "i.attachment") { + return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("attachment %s not found", attachment)) } } diff --git a/pkg/services/attachments.go b/pkg/services/attachments.go index 585b769..79fb06e 100644 --- a/pkg/services/attachments.go +++ b/pkg/services/attachments.go @@ -18,3 +18,12 @@ func GetAttachmentByUUID(uuid string) (*pcpb.Attachment, error) { Uuid: &uuid, }) } + +func CheckAttachmentByUUIDExists(uuid string, usage string) bool { + _, err := grpc.Attachments.CheckAttachmentExists(context.Background(), &pcpb.AttachmentLookupRequest{ + Uuid: &uuid, + Usage: &usage, + }) + + return err == nil +} diff --git a/pkg/services/posts.go b/pkg/services/posts.go index c5f5859..d436694 100644 --- a/pkg/services/posts.go +++ b/pkg/services/posts.go @@ -55,13 +55,10 @@ func GetPostWithAlias(alias string, ignoreLimitation ...bool) (models.Post, erro if err := tx. Where("alias = ?", alias). Preload("Author"). - Preload("Attachments"). Preload("ReplyTo"). Preload("ReplyTo.Author"). - Preload("ReplyTo.Attachments"). Preload("RepostTo"). Preload("RepostTo.Author"). - Preload("RepostTo.Attachments"). First(&item).Error; err != nil { return item, err } @@ -79,13 +76,10 @@ func GetPost(id uint, ignoreLimitation ...bool) (models.Post, error) { if err := tx. Where("id = ?", id). Preload("Author"). - Preload("Attachments"). Preload("ReplyTo"). Preload("ReplyTo.Author"). - Preload("ReplyTo.Attachments"). Preload("RepostTo"). Preload("RepostTo.Author"). - Preload("RepostTo.Attachments"). First(&item).Error; err != nil { return item, err } @@ -157,13 +151,10 @@ func ListPost(tx *gorm.DB, take int, offset int, noReact ...bool) ([]models.Post Limit(take).Offset(offset). Order("created_at DESC"). Preload("Author"). - Preload("Attachments"). Preload("ReplyTo"). Preload("ReplyTo.Author"). - Preload("ReplyTo.Attachments"). Preload("RepostTo"). Preload("RepostTo.Author"). - Preload("RepostTo.Attachments"). Find(&items).Error; err != nil { return items, err }