Removal of saving user settings as a local file
This commit is contained in:
parent
b02c2829c7
commit
54e72c3151
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -11,5 +11,4 @@
|
|||
tmp
|
||||
config.ini
|
||||
|
||||
hide_*
|
||||
UserStorage
|
||||
hide_*
|
|
@ -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{})
|
||||
}
|
||||
|
|
10
main.go
10
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))
|
||||
|
|
Loading…
Reference in New Issue
Block a user