From 54e72c315103a6e7cb05ddcf02e35f7daaabba51 Mon Sep 17 00:00:00 2001 From: 2vb <2vb@protonmail.com> Date: Sun, 31 Dec 2023 05:14:24 -0800 Subject: [PATCH] Removal of saving user settings as a local file --- .gitignore | 3 +- handlers/storage.go | 70 +-------------------------------------------- main.go | 10 +++---- 3 files changed, 7 insertions(+), 76 deletions(-) diff --git a/.gitignore b/.gitignore index 92a0214..82b125c 100644 --- a/.gitignore +++ b/.gitignore @@ -11,5 +11,4 @@ tmp config.ini -hide_* -UserStorage \ No newline at end of file +hide_* \ No newline at end of file diff --git a/handlers/storage.go b/handlers/storage.go index b1c6dbc..b631fed 100644 --- a/handlers/storage.go +++ b/handlers/storage.go @@ -3,9 +3,6 @@ package handlers import ( "crypto/sha1" "encoding/hex" - "io" - "os" - "strings" "github.com/ectrc/snow/aid" "github.com/gofiber/fiber/v2" @@ -147,78 +144,13 @@ func GetCloudStorageFile(c *fiber.Ctx) error { } func GetUserStorageFiles(c *fiber.Ctx) error { - basePath := "UserStorage/" + c.Params("accountId") + "/" - if _, err := os.Stat(basePath); os.IsNotExist(err) { - if err := os.MkdirAll(basePath, 0755); err != nil { - return c.Status(fiber.StatusInternalServerError).JSON(aid.ErrorInternalServer) - } - } else { - filePath := basePath - fileContent, err := os.ReadFile(filePath + "ClientSettings.Sav") - if err != nil { - return c.Status(fiber.StatusOK).JSON(aid.JSON{}) - } - settingsHash := sha1.Sum(fileContent) - settingsHash256 := sha1.Sum(fileContent) - return c.Status(fiber.StatusOK).JSON(aid.JSON{ - "uniqueFilename": "ClientSettings.Sav", - "filename": "ClientSettings.Sav", - "hash": hex.EncodeToString(settingsHash[:]), - "hash256": hex.EncodeToString(settingsHash256[:]), - "length": len(fileContent), - "contentType": "application/octet-stream", - "uploaded": "2021-01-01T00:00:00.000Z", - "storageType": "S3", - "doNotCache": false, - "storageIds": []string{"primary"}, - }) - } - return c.Status(fiber.StatusOK).JSON(aid.JSON{}) + return c.Status(fiber.StatusOK).JSON([]aid.JSON{}) } func GetUserStorageFile(c *fiber.Ctx) error { - basePath := "UserStorage/" + c.Params("accountId") + "/" - if _, err := os.Stat(basePath); os.IsNotExist(err) { - if err := os.MkdirAll(basePath, 0755); err != nil { return c.Status(fiber.StatusOK).JSON(aid.JSON{}) - } - } else { - filePath := basePath + c.Params("fileName") - _, err := os.Stat(filePath) - if err != nil { - return c.Status(fiber.StatusInternalServerError).JSON(aid.ErrorNotFound) - } else { - return c.Status(fiber.StatusOK).SendFile(filePath) - } - - } - return c.Status(fiber.StatusInternalServerError).JSON(aid.ErrorInternalServer) } func PutUserStorageFile(c *fiber.Ctx) error { - bytes := string(c.BodyRaw()) - - if c.Request().Header.ContentLength() > 400000 || strings.ToLower(c.Params("fileName")) != "clientsettings.sav" { - return c.Status(fiber.StatusBadRequest).JSON(aid.ErrorBadRequest("Invalid File")) - } - - filePath := "UserStorage/" + c.Params("accountId") + "/" - if _, err := os.Stat(filePath); os.IsNotExist(err) { - if err := os.MkdirAll(filePath, 0755); err != nil { - return c.Status(fiber.StatusInternalServerError).JSON(aid.ErrorInternalServer) - } - } - - file, err := os.Create(filePath + c.Params("fileName")) - if err != nil { - return c.Status(fiber.StatusInternalServerError).JSON(aid.ErrorInternalServer) - } - defer file.Close() - - _, err = io.Copy(file, strings.NewReader(bytes)) - if err != nil { - return c.Status(fiber.StatusInternalServerError).JSON(aid.ErrorInternalServer) - } - return c.Status(fiber.StatusOK).JSON(aid.JSON{}) } diff --git a/main.go b/main.go index 8532896..a51a3dc 100644 --- a/main.go +++ b/main.go @@ -20,7 +20,7 @@ var configFile []byte func init() { aid.LoadConfig(configFile) - + var device storage.Storage switch aid.Config.Database.Type { case "postgres": @@ -97,7 +97,7 @@ func main() { 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) @@ -120,7 +120,7 @@ func main() { discord := snow.Group("/discord") discord.Get("/", handlers.GetDiscordOAuthURL) - + player := snow.Group("/player") player.Use(handlers.MiddlewareWeb) player.Get("/", handlers.GetPlayer) @@ -130,9 +130,9 @@ func main() { aid.Print("Listening on " + aid.Config.API.Host + ":" + ld.Port) return nil }) - + r.All("*", func(c *fiber.Ctx) error { return c.Status(fiber.StatusNotFound).JSON(aid.ErrorNotFound) }) - + err := r.Listen("0.0.0.0" + aid.Config.API.Port) if err != nil { panic(fmt.Sprintf("Failed to listen: %v", err))