Compare commits

..

2 Commits

Author SHA1 Message Date
4c5d6d5ec5 👔 Sticker creation & edit will no longer check metadta 2024-08-06 15:41:41 +08:00
8b3a7d6324 🐛 Fix manifest won't filter by author 2024-08-06 15:29:38 +08:00
3 changed files with 17 additions and 16 deletions

View File

@ -17,12 +17,24 @@ func listStickerManifest(c *fiber.Ctx) error {
take = 100 take = 100
} }
tx := database.C
if len(c.Query("author")) > 0 {
var author models.Account
if err := database.C.Where("name = ?", c.Query("author")).First(&author).Error; err != nil {
return fiber.NewError(fiber.StatusBadRequest, err.Error())
} else {
tx = tx.Where("account_id = ?", author.ID)
}
}
var count int64 var count int64
if err := database.C.Model(&models.StickerPack{}).Count(&count).Error; err != nil { countTx := tx
if err := countTx.Model(&models.StickerPack{}).Count(&count).Error; err != nil {
return fiber.NewError(fiber.StatusInternalServerError, err.Error()) return fiber.NewError(fiber.StatusInternalServerError, err.Error())
} }
stickers, err := services.ListStickerPackWithStickers(take, offset) stickers, err := services.ListStickerPackWithStickers(tx, take, offset)
if err != nil { if err != nil {
return fiber.NewError(fiber.StatusInternalServerError, err.Error()) return fiber.NewError(fiber.StatusInternalServerError, err.Error())
} }

View File

@ -86,12 +86,6 @@ func createSticker(c *fiber.Ctx) error {
if strings.SplitN(attachment.MimeType, "/", 2)[0] != "image" { if strings.SplitN(attachment.MimeType, "/", 2)[0] != "image" {
return fiber.NewError(fiber.StatusBadRequest, "sticker attachment must be an image") return fiber.NewError(fiber.StatusBadRequest, "sticker attachment must be an image")
} else if width, ok := attachment.Metadata["width"]; !ok {
return fiber.NewError(fiber.StatusBadRequest, "sticker attachment must has width metadata")
} else if height, ok := attachment.Metadata["height"]; !ok {
return fiber.NewError(fiber.StatusBadRequest, "sticker attachment must has height metadata")
} else if fmt.Sprint(width) != fmt.Sprint(28) || fmt.Sprint(height) != fmt.Sprint(28) {
return fiber.NewError(fiber.StatusBadRequest, "sticker attachment must be a 28x28 image")
} }
var pack models.StickerPack var pack models.StickerPack
@ -146,12 +140,6 @@ func updateSticker(c *fiber.Ctx) error {
if strings.SplitN(attachment.MimeType, "/", 2)[0] != "image" { if strings.SplitN(attachment.MimeType, "/", 2)[0] != "image" {
return fiber.NewError(fiber.StatusBadRequest, "sticker attachment must be an image") return fiber.NewError(fiber.StatusBadRequest, "sticker attachment must be an image")
} else if width, ok := attachment.Metadata["width"]; !ok {
return fiber.NewError(fiber.StatusBadRequest, "sticker attachment must has width metadata")
} else if height, ok := attachment.Metadata["height"]; !ok {
return fiber.NewError(fiber.StatusBadRequest, "sticker attachment must has height metadata")
} else if fmt.Sprint(width) != fmt.Sprint(28) || fmt.Sprint(height) != fmt.Sprint(28) {
return fiber.NewError(fiber.StatusBadRequest, "sticker attachment must be a 28x28 image")
} }
var pack models.StickerPack var pack models.StickerPack

View File

@ -3,6 +3,7 @@ package services
import ( import (
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/database" "git.solsynth.dev/hydrogen/paperclip/pkg/internal/database"
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/models" "git.solsynth.dev/hydrogen/paperclip/pkg/internal/models"
"gorm.io/gorm"
) )
func GetStickerPackWithUser(id, userId uint) (models.StickerPack, error) { func GetStickerPackWithUser(id, userId uint) (models.StickerPack, error) {
@ -13,9 +14,9 @@ func GetStickerPackWithUser(id, userId uint) (models.StickerPack, error) {
return pack, nil return pack, nil
} }
func ListStickerPackWithStickers(take, offset int) ([]models.StickerPack, error) { func ListStickerPackWithStickers(tx *gorm.DB, take, offset int) ([]models.StickerPack, error) {
var packs []models.StickerPack var packs []models.StickerPack
if err := database.C.Limit(take).Offset(offset).Preload("Stickers").Preload("Stickers.Attachment").Find(&packs).Error; err != nil { if err := tx.Limit(take).Offset(offset).Preload("Stickers").Preload("Stickers.Attachment").Find(&packs).Error; err != nil {
return packs, err return packs, err
} }
return packs, nil return packs, nil