Able to directly open (get the image) of a sticker

This commit is contained in:
2025-01-06 21:51:26 +08:00
parent 8cd1037759
commit 8bcf02fa5e
2 changed files with 35 additions and 3 deletions

View File

@@ -2,10 +2,11 @@ package api
import (
"fmt"
"strings"
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/gap"
"git.solsynth.dev/hypernet/passport/pkg/authkit"
"strings"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/models"
@@ -23,7 +24,7 @@ func lookupStickerBatch(c *fiber.Ctx) error {
}
}
func lookupSticker(c *fiber.Ctx) error {
func getStickerByAlias(c *fiber.Ctx) error {
alias := c.Params("alias")
if sticker, err := services.GetStickerWithAlias(alias); err != nil {
return fiber.NewError(fiber.StatusNotFound, err.Error())
@@ -32,6 +33,36 @@ func lookupSticker(c *fiber.Ctx) error {
}
}
func openStickerByAlias(c *fiber.Ctx) error {
alias := c.Params("alias")
region := c.Query("region")
sticker, err := services.GetStickerWithAlias(alias)
if err != nil {
return fiber.NewError(fiber.StatusNotFound, err.Error())
}
var url, mimetype string
if len(region) > 0 {
url, mimetype, err = services.OpenAttachmentByRID(sticker.Attachment.Rid, region)
} else {
url, mimetype, err = services.OpenAttachmentByRID(sticker.Attachment.Rid)
}
if err != nil {
return fiber.NewError(fiber.StatusNotFound, err.Error())
}
c.Set(fiber.HeaderContentType, mimetype)
if strings.HasPrefix(url, "file://") {
fp := strings.Replace(url, "file://", "", 1)
return c.SendFile(fp)
}
return c.Redirect(url, fiber.StatusFound)
}
func listStickers(c *fiber.Ctx) error {
take := c.QueryInt("take", 0)
offset := c.QueryInt("offset", 0)