snow/handlers/snow.go

63 lines
1.2 KiB
Go
Raw Normal View History

package handlers
import (
2023-12-07 23:25:17 +00:00
"strings"
2023-12-10 01:55:11 +00:00
"github.com/ectrc/snow/aid"
"github.com/ectrc/snow/fortnite"
2023-12-10 01:55:11 +00:00
p "github.com/ectrc/snow/person"
"github.com/gofiber/fiber/v2"
)
2023-12-07 23:25:17 +00:00
func GetPreloadedCosmetics(c *fiber.Ctx) error {
return c.JSON(fortnite.Cosmetics)
2023-12-07 23:25:17 +00:00
}
func GetPlaylistImage(c *fiber.Ctx) error {
playlist := c.Params("playlist")
if playlist == "" {
return c.SendStatus(404)
}
playlist = strings.Split(playlist, ".")[0]
image, ok := fortnite.PlaylistImages[playlist]
if !ok {
return c.SendStatus(404)
}
c.Set("Content-Type", "image/png")
return c.Send(image)
}
2023-12-09 15:35:33 +00:00
func GetPlayerLocker(c *fiber.Ctx) error {
2023-12-10 01:55:11 +00:00
person := c.Locals("person").(*p.Person)
items := make([]p.Item, 0)
person.AthenaProfile.Items.RangeItems(func(key string, value *p.Item) bool {
items = append(items, *value)
return true
})
return c.JSON(items)
}
func GetPlayer(c *fiber.Ctx) error {
person := c.Locals("person").(*p.Person)
return c.JSON(aid.JSON{
"id": person.ID,
"displayName": person.DisplayName,
"discord": person.Discord,
})
2024-02-03 15:08:16 +00:00
}
func GetCachedPlayers(c *fiber.Ctx) error {
persons := p.AllFromCache()
players := make([]p.PersonSnapshot, len(persons))
for i, person := range persons {
players[i] = *person.Snapshot()
}
return c.JSON(players)
2023-12-09 15:35:33 +00:00
}