snow/handlers/storefront.go

58 lines
1.4 KiB
Go
Raw Normal View History

package handlers
import (
2024-02-19 04:07:40 +00:00
"strings"
"github.com/goccy/go-json"
2023-11-09 18:42:28 +00:00
"github.com/ectrc/snow/aid"
"github.com/ectrc/snow/fortnite"
2023-11-09 18:42:28 +00:00
"github.com/ectrc/snow/storage"
"github.com/gofiber/fiber/v2"
)
func GetStorefrontCatalog(c *fiber.Ctx) error {
2024-02-18 00:09:02 +00:00
shop := fortnite.NewRandomFortniteCatalog()
2024-02-19 04:07:40 +00:00
return c.Status(200).JSON(shop.GenerateFortniteCatalogResponse())
}
func GetStorefrontKeychain(c *fiber.Ctx) error {
2023-11-09 18:42:28 +00:00
var keychain []string
err := json.Unmarshal(*storage.Asset("keychain.json"), &keychain)
if err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(aid.JSON{"error":err.Error()})
}
2024-02-18 00:09:02 +00:00
return c.Status(200).JSON(keychain)
2024-02-19 04:07:40 +00:00
}
func GetStorefrontCatalogBulkOffers(c *fiber.Ctx) error {
shop := fortnite.NewRandomFortniteCatalog()
appStoreIdBytes := c.Request().URI().QueryArgs().PeekMulti("id")
appStoreIds := make([]string, len(appStoreIdBytes))
for i, id := range appStoreIdBytes {
appStoreIds[i] = string(id)
}
response := aid.JSON{}
for _, id := range appStoreIds {
offer := shop.FindCurrencyOfferById(strings.ReplaceAll(id, "app-", ""))
if offer == nil {
continue
}
response[id] = offer.GenerateFortniteCatalogBulkOfferResponse()
}
2024-02-19 16:08:37 +00:00
for _, id := range appStoreIds {
offer := shop.FindStarterPackById(strings.ReplaceAll(id, "app-", ""))
if offer == nil {
continue
}
response[id] = offer.GenerateFortniteCatalogBulkOfferResponse()
}
2024-02-19 04:07:40 +00:00
return c.Status(200).JSON(response)
}