2023-11-05 22:08:53 +00:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
2023-11-09 18:53:19 +00:00
|
|
|
"github.com/goccy/go-json"
|
2023-11-09 18:42:28 +00:00
|
|
|
|
2023-11-05 22:08:53 +00:00
|
|
|
"github.com/ectrc/snow/aid"
|
2024-03-10 18:16:42 +00:00
|
|
|
"github.com/ectrc/snow/shop"
|
2023-11-09 18:42:28 +00:00
|
|
|
"github.com/ectrc/snow/storage"
|
2023-11-05 22:08:53 +00:00
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
func GetStorefrontCatalog(c *fiber.Ctx) error {
|
2024-03-10 18:16:42 +00:00
|
|
|
shop := shop.GetShop()
|
2024-02-19 04:07:40 +00:00
|
|
|
return c.Status(200).JSON(shop.GenerateFortniteCatalogResponse())
|
2023-11-05 22:08:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2024-03-10 18:16:42 +00:00
|
|
|
store := shop.GetShop()
|
2024-02-19 04:07:40 +00:00
|
|
|
|
|
|
|
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 {
|
2024-03-10 18:16:42 +00:00
|
|
|
offerRaw, type_ := store.GetOfferByID(id)
|
|
|
|
if offerRaw == nil {
|
2024-02-19 04:07:40 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2024-03-10 18:16:42 +00:00
|
|
|
switch type_ {
|
|
|
|
case shop.StorefrontCatalogOfferEnumCurrency:
|
|
|
|
offer := offerRaw.(*shop.StorefrontCatalogOfferTypeCurrency)
|
|
|
|
response[id] = offer.GenerateFortniteBulkOffersResponse()
|
|
|
|
case shop.StorefrontCatalogOfferEnumStarterKit:
|
|
|
|
offer := offerRaw.(*shop.StorefrontCatalogOfferTypeStarterKit)
|
|
|
|
response[id] = offer.GenerateFortniteBulkOffersResponse()
|
|
|
|
default:
|
|
|
|
break
|
2024-02-19 16:08:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-19 04:07:40 +00:00
|
|
|
return c.Status(200).JSON(response)
|
2023-11-05 22:08:53 +00:00
|
|
|
}
|