Compare commits
No commits in common. "4c5d6d5ec59e678c8c39b9932116995b2acaf0d7" and "dc57261b2eb8889657326b0ab0efa61b8fc8d3b3" have entirely different histories.
4c5d6d5ec5
...
dc57261b2e
@ -17,24 +17,12 @@ 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
|
||||||
countTx := tx
|
if err := database.C.Model(&models.StickerPack{}).Count(&count).Error; err != nil {
|
||||||
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(tx, take, offset)
|
stickers, err := services.ListStickerPackWithStickers(take, offset)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||||
}
|
}
|
||||||
|
@ -86,6 +86,12 @@ 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
|
||||||
@ -140,6 +146,12 @@ 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
|
||||||
|
@ -3,7 +3,6 @@ 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) {
|
||||||
@ -14,9 +13,9 @@ func GetStickerPackWithUser(id, userId uint) (models.StickerPack, error) {
|
|||||||
return pack, nil
|
return pack, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ListStickerPackWithStickers(tx *gorm.DB, take, offset int) ([]models.StickerPack, error) {
|
func ListStickerPackWithStickers(take, offset int) ([]models.StickerPack, error) {
|
||||||
var packs []models.StickerPack
|
var packs []models.StickerPack
|
||||||
if err := tx.Limit(take).Offset(offset).Preload("Stickers").Preload("Stickers.Attachment").Find(&packs).Error; err != nil {
|
if err := database.C.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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user