2023-10-31 22:40:14 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-10-31 23:19:52 +00:00
|
|
|
"github.com/ectrc/snow/aid"
|
2023-11-03 23:48:50 +00:00
|
|
|
"github.com/ectrc/snow/handlers"
|
2023-10-31 22:40:14 +00:00
|
|
|
"github.com/ectrc/snow/person"
|
|
|
|
"github.com/ectrc/snow/storage"
|
2023-11-03 23:48:50 +00:00
|
|
|
|
|
|
|
"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-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.Migrate(&storage.DB_Person{}, "Persons")
|
|
|
|
postgresStorage.Migrate(&storage.DB_Profile{}, "Profiles")
|
|
|
|
postgresStorage.Migrate(&storage.DB_Item{}, "Items")
|
|
|
|
postgresStorage.Migrate(&storage.DB_Gift{}, "Gifts")
|
|
|
|
postgresStorage.Migrate(&storage.DB_Quest{}, "Quests")
|
|
|
|
postgresStorage.Migrate(&storage.DB_Loot{}, "Loot")
|
|
|
|
postgresStorage.Migrate(&storage.DB_VariantChannel{}, "Variants")
|
|
|
|
postgresStorage.Migrate(&storage.DB_PAttribute{}, "Attributes")
|
|
|
|
|
|
|
|
device = postgresStorage
|
|
|
|
}
|
2023-10-31 23:19:52 +00:00
|
|
|
|
2023-10-31 22:40:14 +00:00
|
|
|
storage.Repo = storage.NewStorage(device)
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2023-11-03 23:48:50 +00:00
|
|
|
if aid.Config.Database.DropAllTables {
|
2023-11-05 01:58:00 +00:00
|
|
|
person.NewFortnitePerson("ac", "1")
|
2023-11-03 23:48:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
aid.PrintTime("Loading all persons from database", func() {
|
|
|
|
for _, person := range person.AllFromDatabase() {
|
|
|
|
aid.Print("Loaded person: " + person.DisplayName)
|
|
|
|
}
|
|
|
|
})
|
2023-11-05 02:43:21 +00:00
|
|
|
|
|
|
|
aid.PrintTime("Loading all persons from cache", func() {
|
|
|
|
for _, person := range person.AllFromCache() {
|
|
|
|
aid.Print("Loaded person: " + person.DisplayName)
|
|
|
|
}
|
|
|
|
})
|
2023-10-31 22:40:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2023-11-03 23:48:50 +00:00
|
|
|
r := fiber.New()
|
|
|
|
|
|
|
|
r.Use(aid.FiberLogger())
|
|
|
|
r.Use(aid.FiberLimiter())
|
|
|
|
r.Use(aid.FiberCors())
|
|
|
|
|
2023-11-05 01:58:00 +00:00
|
|
|
r.Get("/content/api/pages/fortnite-game", handlers.GetContentPages)
|
|
|
|
|
2023-11-03 23:48:50 +00:00
|
|
|
account := r.Group("/account/api")
|
|
|
|
account.Get("/public/account/:accountId", handlers.GetPublicAccount)
|
|
|
|
account.Get("/public/account/:accountId/externalAuths", handlers.GetPublicAccountExternalAuths)
|
|
|
|
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.GetAccountReceipts)
|
|
|
|
fortnite.Get("/versioncheck/*", handlers.GetVersionCheck)
|
2023-11-05 01:58:00 +00:00
|
|
|
fortnite.Get("/calendar/v1/timeline", handlers.GetTimelineCalendar)
|
2023-11-03 23:48:50 +00:00
|
|
|
|
|
|
|
matchmaking := fortnite.Group("/matchmaking")
|
|
|
|
matchmaking.Get("/session/findPlayer/:accountId", handlers.GetSessionFindPlayer)
|
|
|
|
|
|
|
|
storage := fortnite.Group("/cloudstorage")
|
|
|
|
storage.Get("/system", handlers.GetCloudStorageFiles)
|
|
|
|
storage.Get("/system/config", handlers.GetCloudStorageConfig)
|
|
|
|
storage.Get("/system/:fileName", handlers.GetCloudStorageFile)
|
2023-11-05 01:58:00 +00:00
|
|
|
storage.Get("/user/:accountId", handlers.GetUserStorageFiles)
|
|
|
|
storage.Get("/user/:accountId/:fileName", handlers.GetUserStorageFile)
|
|
|
|
storage.Put("/user/:accountId/:fileName", handlers.PutUserStorageFile)
|
2023-11-03 23:48:50 +00:00
|
|
|
|
|
|
|
game := fortnite.Group("/game/v2")
|
|
|
|
game.Post("/tryPlayOnPlatform/account/:accountId", handlers.PostTryPlayOnPlatform)
|
|
|
|
game.Post("/grant_access/:accountId", handlers.PostGrantAccess)
|
|
|
|
game.Get("/enabled_features", handlers.GetEnabledFeatures)
|
|
|
|
|
|
|
|
profile := game.Group("/profile/:accountId")
|
|
|
|
profile.Post("/client/:action", handlers.PostProfileAction)
|
|
|
|
|
|
|
|
lightswitch := r.Group("/lightswitch/api")
|
|
|
|
lightswitch.Get("/service/bulk/status", handlers.GetLightswitchBulkStatus)
|
2023-11-01 21:33:25 +00:00
|
|
|
|
2023-11-03 23:48:50 +00:00
|
|
|
r.All("*", func(c *fiber.Ctx) error { return c.Status(fiber.StatusNotFound).JSON(aid.ErrorNotFound) })
|
|
|
|
r.Listen(aid.Config.API.Host + aid.Config.API.Port)
|
2023-10-31 22:40:14 +00:00
|
|
|
}
|