✨ Able to directly open (get the image) of a sticker
This commit is contained in:
		@@ -49,7 +49,8 @@ func MapAPIs(app *fiber.App, baseURL string) {
 | 
				
			|||||||
		stickers := api.Group("/stickers").Name("Stickers API")
 | 
							stickers := api.Group("/stickers").Name("Stickers API")
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			stickers.Get("/lookup", lookupStickerBatch)
 | 
								stickers.Get("/lookup", lookupStickerBatch)
 | 
				
			||||||
			stickers.Get("/lookup/:alias", lookupSticker)
 | 
								stickers.Get("/lookup/:alias", getStickerByAlias)
 | 
				
			||||||
 | 
								stickers.Get("/lookup/:alias/open", openStickerByAlias)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			stickers.Get("/", listStickers)
 | 
								stickers.Get("/", listStickers)
 | 
				
			||||||
			stickers.Get("/:stickerId", getSticker)
 | 
								stickers.Get("/:stickerId", getSticker)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,10 +2,11 @@ package api
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
 | 
						"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
 | 
				
			||||||
	"git.solsynth.dev/hypernet/paperclip/pkg/internal/gap"
 | 
						"git.solsynth.dev/hypernet/paperclip/pkg/internal/gap"
 | 
				
			||||||
	"git.solsynth.dev/hypernet/passport/pkg/authkit"
 | 
						"git.solsynth.dev/hypernet/passport/pkg/authkit"
 | 
				
			||||||
	"strings"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
 | 
						"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
 | 
				
			||||||
	"git.solsynth.dev/hypernet/paperclip/pkg/internal/models"
 | 
						"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")
 | 
						alias := c.Params("alias")
 | 
				
			||||||
	if sticker, err := services.GetStickerWithAlias(alias); err != nil {
 | 
						if sticker, err := services.GetStickerWithAlias(alias); err != nil {
 | 
				
			||||||
		return fiber.NewError(fiber.StatusNotFound, err.Error())
 | 
							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 {
 | 
					func listStickers(c *fiber.Ctx) error {
 | 
				
			||||||
	take := c.QueryInt("take", 0)
 | 
						take := c.QueryInt("take", 0)
 | 
				
			||||||
	offset := c.QueryInt("offset", 0)
 | 
						offset := c.QueryInt("offset", 0)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user