snow/main.go

124 lines
4.1 KiB
Go
Raw Normal View History

2023-10-31 22:40:14 +00:00
package main
import (
2023-12-07 19:29:47 +00:00
"fmt"
"github.com/ectrc/snow/aid"
2023-11-21 23:42:39 +00:00
"github.com/ectrc/snow/fortnite"
"github.com/ectrc/snow/handlers"
2023-10-31 22:40:14 +00:00
"github.com/ectrc/snow/storage"
"github.com/goccy/go-json"
"github.com/gofiber/fiber/v2"
2023-10-31 22:40:14 +00:00
)
func init() {
2023-11-01 21:51:14 +00:00
aid.LoadConfig()
2023-11-08 22:09:08 +00:00
2023-10-31 22:40:14 +00:00
var device storage.Storage
2023-11-01 21:51:14 +00:00
switch aid.Config.Database.Type {
2023-10-31 22:40:14 +00:00
case "postgres":
postgresStorage := storage.NewPostgresStorage()
2023-11-02 17:50:52 +00:00
if aid.Config.Database.DropAllTables {
aid.Print("Dropping all tables")
2023-10-31 22:40:14 +00:00
postgresStorage.DropTables()
}
postgresStorage.MigrateAll()
2023-10-31 22:40:14 +00:00
device = postgresStorage
2023-12-07 19:29:47 +00:00
default:
panic("Invalid database type: " + aid.Config.Database.Type)
2023-10-31 22:40:14 +00:00
}
2023-10-31 22:40:14 +00:00
storage.Repo = storage.NewStorage(device)
}
func init() {
fortnite.PreloadCosmetics(aid.Config.Fortnite.Season)
2023-12-06 22:26:42 +00:00
fortnite.GenerateRandomStorefront()
if aid.Config.Database.DropAllTables {
2023-11-21 23:42:39 +00:00
fortnite.NewFortnitePerson("ac", "1")
}
2023-12-07 23:25:17 +00:00
fortnite.GenerateSoloImage()
2023-10-31 22:40:14 +00:00
}
func main() {
r := fiber.New(fiber.Config{
DisableStartupMessage: true,
JSONEncoder: json.Marshal,
JSONDecoder: json.Unmarshal,
})
r.Use(aid.FiberLogger())
r.Use(aid.FiberLimiter())
r.Use(aid.FiberCors())
r.Get("/content/api/pages/fortnite-game", handlers.GetContentPages)
r.Get("/waitingroom/api/waitingroom", handlers.GetWaitingRoomStatus)
r.Get("/region", handlers.GetRegion)
r.Put("/profile/play_region", handlers.AnyNoContent)
r.Post("/api/v1/assets/Fortnite/:versionId/:assetName", handlers.PostAssets)
account := r.Group("/account/api")
2023-11-09 18:42:28 +00:00
account.Get("/public/account", handlers.GetPublicAccounts)
account.Get("/public/account/:accountId", handlers.GetPublicAccount)
account.Get("/public/account/:accountId/externalAuths", handlers.GetPublicAccountExternalAuths)
2023-11-09 18:42:28 +00:00
account.Get("/public/account/displayName/:displayName", handlers.GetPublicAccountByDisplayName)
account.Get("/oauth/verify", handlers.GetOAuthVerify)
account.Post("/oauth/token", handlers.PostOAuthToken)
account.Delete("/oauth/sessions/kill", handlers.DeleteOAuthSessions)
fortnite := r.Group("/fortnite/api")
fortnite.Get("/receipts/v1/account/:accountId/receipts", handlers.GetFortniteReceipts)
fortnite.Get("/v2/versioncheck/*", handlers.GetFortniteVersion)
fortnite.Get("/calendar/v1/timeline", handlers.GetFortniteTimeline)
storefront := fortnite.Group("/storefront/v2")
storefront.Use(handlers.OAuthMiddleware)
storefront.Get("/catalog", handlers.GetStorefrontCatalog)
storefront.Get("/keychain", handlers.GetStorefrontKeychain)
matchmaking := fortnite.Group("/matchmaking")
matchmaking.Get("/session/findPlayer/:accountId", handlers.GetMatchmakingSession)
storage := fortnite.Group("/cloudstorage")
storage.Get("/system", handlers.GetCloudStorageFiles)
storage.Get("/system/config", handlers.GetCloudStorageConfig)
storage.Get("/system/:fileName", handlers.GetCloudStorageFile)
2023-11-09 18:42:28 +00:00
user := storage.Group("/user")
user.Use(handlers.OAuthMiddleware)
2023-11-09 18:42:28 +00:00
user.Get("/:accountId", handlers.GetUserStorageFiles)
user.Get("/:accountId/:fileName", handlers.GetUserStorageFile)
user.Put("/:accountId/:fileName", handlers.PutUserStorageFile)
game := fortnite.Group("/game/v2")
game.Get("/enabled_features", handlers.GetGameEnabledFeatures)
game.Post("/tryPlayOnPlatform/account/:accountId", handlers.PostGamePlatform)
game.Post("/grant_access/:accountId", handlers.PostGameAccess)
game.Post("/creative/discovery/surface/:accountId", handlers.PostDiscovery)
2023-11-19 22:20:00 +00:00
game.Post("/profileToken/verify/:accountId", handlers.AnyNoContent)
profile := game.Group("/profile/:accountId")
profile.Use(handlers.OAuthMiddleware)
profile.Post("/client/:action", handlers.PostProfileAction)
lightswitch := r.Group("/lightswitch/api")
lightswitch.Get("/service/bulk/status", handlers.GetLightswitchBulkStatus)
snow := r.Group("/snow")
2023-12-07 23:25:17 +00:00
snow.Get("/cosmetics", handlers.GetPreloadedCosmetics)
snow.Get("/image/:playlist", handlers.GetPlaylistImage)
r.Hooks().OnListen(func(ld fiber.ListenData) error {
2023-12-07 23:25:17 +00:00
aid.Print("Listening on " + "0.0.0.0:" + ld.Port)
return nil
})
2023-12-07 19:29:47 +00:00
r.All("*", func(c *fiber.Ctx) error { return c.Status(fiber.StatusNotFound).JSON(aid.ErrorNotFound) })
2023-12-07 19:29:47 +00:00
err := r.Listen(aid.Config.API.Host + aid.Config.API.Port)
if err != nil {
panic(fmt.Sprintf("Failed to listen: %v", err))
}
2023-10-31 22:40:14 +00:00
}