snow/handlers/snow.go

77 lines
1.6 KiB
Go
Raw Normal View History

package handlers
import (
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"
2024-02-04 19:49:31 +00:00
"github.com/ectrc/snow/storage"
"github.com/gofiber/fiber/v2"
)
func MiddlewareOnlyDebug(c *fiber.Ctx) error {
if aid.Config.API.Debug {
return c.Next()
2023-12-07 23:25:17 +00:00
}
return c.SendStatus(403)
}
2024-02-12 20:29:02 +00:00
func GetSnowPreloadedCosmetics(c *fiber.Ctx) error {
return c.JSON(fortnite.External)
2023-12-07 23:25:17 +00:00
}
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
}
2024-02-12 20:29:02 +00:00
func GetSnowCachedPlayers(c *fiber.Ctx) error {
2024-02-03 15:08:16 +00:00
persons := p.AllFromCache()
players := make([]p.PersonSnapshot, len(persons))
for i, person := range persons {
players[i] = *person.Snapshot()
}
return c.JSON(players)
2024-02-04 19:49:31 +00:00
}
func GetSnowConfig(c *fiber.Ctx) error {
return c.JSON(aid.JSON{
"basic": aid.Config,
"amazon": storage.Repo.Amazon,
})
}
2024-02-12 20:29:02 +00:00
func GetSnowParties(c *fiber.Ctx) error {
parties := []aid.JSON{}
p.Parties.Range(func(key string, value *p.Party) bool {
parties = append(parties, value.GenerateFortniteParty())
return true
})
return c.JSON(parties)
}
func GetSnowShop(c *fiber.Ctx) error {
2024-02-18 00:09:02 +00:00
shop := fortnite.NewRandomFortniteCatalog()
return c.JSON(shop.GenerateFortniteCatalog())
2024-02-12 20:29:02 +00:00
}