🐛 Fix getting count of stickers in pack

This commit is contained in:
LittleSheep 2024-09-25 22:28:08 +08:00
parent f7ab3bfb18
commit fa997a19a1
4 changed files with 2 additions and 47 deletions

View File

@ -25,7 +25,6 @@ func MapAPIs(app *fiber.App, baseURL string) {
api.Get("/stickers/lookup", lookupStickerBatch) api.Get("/stickers/lookup", lookupStickerBatch)
api.Get("/stickers/lookup/:alias", lookupSticker) api.Get("/stickers/lookup/:alias", lookupSticker)
api.Get("/stickers/manifest", listStickerManifest)
api.Get("/stickers/packs", listStickerPacks) api.Get("/stickers/packs", listStickerPacks)
api.Post("/stickers/packs", createStickerPack) api.Post("/stickers/packs", createStickerPack)
api.Put("/stickers/packs/:packId", updateStickerPack) api.Put("/stickers/packs/:packId", updateStickerPack)

View File

@ -9,42 +9,6 @@ import (
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
) )
func listStickerManifest(c *fiber.Ctx) error {
take := c.QueryInt("take", 0)
offset := c.QueryInt("offset", 0)
if 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
countTx := tx
if err := countTx.Model(&models.StickerPack{}).Count(&count).Error; err != nil {
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
}
stickers, err := services.ListStickerPackWithStickers(tx, take, offset)
if err != nil {
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
}
return c.JSON(fiber.Map{
"count": count,
"data": stickers,
})
}
func listStickerPacks(c *fiber.Ctx) error { func listStickerPacks(c *fiber.Ctx) error {
take := c.QueryInt("take", 0) take := c.QueryInt("take", 0)
offset := c.QueryInt("offset", 0) offset := c.QueryInt("offset", 0)

View File

@ -54,7 +54,8 @@ func listStickers(c *fiber.Ctx) error {
} }
var count int64 var count int64
if err := database.C.Model(&models.Sticker{}).Count(&count).Error; err != nil { countTx := tx
if err := countTx.Model(&models.Sticker{}).Count(&count).Error; err != nil {
return fiber.NewError(fiber.StatusInternalServerError, err.Error()) return fiber.NewError(fiber.StatusInternalServerError, err.Error())
} }

View File

@ -2,15 +2,6 @@ id = "paperclip01"
bind = "0.0.0.0:8443" bind = "0.0.0.0:8443"
grpc_bind = "0.0.0.0:7443" grpc_bind = "0.0.0.0:7443"
domain = "usercontent.solsynth.dev"
accepts_usage = [
"p.avatar",
"p.banner",
"i.attachment",
"m.attachment",
"sticker",
]
[workers] [workers]
files_deletion = 4 files_deletion = 4