snow/handlers/storage.go

80 lines
1.8 KiB
Go
Raw Normal View History

package handlers
import (
2024-01-04 19:02:14 +00:00
"crypto/sha1"
"crypto/sha256"
"encoding/hex"
"github.com/ectrc/snow/aid"
2024-01-04 19:02:14 +00:00
"github.com/ectrc/snow/storage"
"github.com/gofiber/fiber/v2"
)
func GetCloudStorageFiles(c *fiber.Ctx) error {
2024-01-31 16:20:26 +00:00
files := map[string][]byte {
"DefaultEngine.ini": storage.GetDefaultEngine(),
"DefaultGame.ini": storage.GetDefaultGame(),
"DefaultRuntimeOptions.ini": storage.GetDefaultRuntime(),
}
result := []aid.JSON{}
for name, data := range files {
sumation1 := sha1.Sum(data)
sumation256 := sha256.Sum256(data)
2024-01-04 19:02:14 +00:00
2024-01-31 16:20:26 +00:00
result = append(result, aid.JSON{
"uniqueFilename": name,
"filename": name,
"hash": hex.EncodeToString(sumation1[:]),
"hash256": hex.EncodeToString(sumation256[:]),
"length": len(data),
2024-01-04 19:02:14 +00:00
"contentType": "application/octet-stream",
2024-01-20 01:58:57 +00:00
"uploaded": aid.TimeStartOfDay(),
2024-01-04 19:02:14 +00:00
"storageType": "S3",
2024-01-31 16:20:26 +00:00
"storageIds": aid.JSON{
2024-01-20 01:58:57 +00:00
"primary": "primary",
},
2024-01-04 19:02:14 +00:00
"doNotCache": false,
2024-01-31 16:20:26 +00:00
})
}
return c.Status(fiber.StatusOK).JSON(result)
}
func GetCloudStorageConfig(c *fiber.Ctx) error {
2024-01-31 16:20:26 +00:00
return c.Status(fiber.StatusOK).JSON(aid.JSON{
"enumerateFilesPath": "/api/cloudstorage/system",
2023-12-27 04:35:12 +00:00
"enableMigration": true,
"enableWrites": true,
"epicAppName": "Live",
"isAuthenticated": true,
"disableV2": true,
2024-01-20 01:58:57 +00:00
"lastUpdated": aid.TimeStartOfDay(),
2023-12-27 04:35:12 +00:00
"transports": []string{},
})
}
func GetCloudStorageFile(c *fiber.Ctx) error {
2024-01-04 19:02:14 +00:00
switch c.Params("fileName") {
case "DefaultEngine.ini":
2024-01-20 01:58:57 +00:00
c.Set("Content-Type", "application/octet-stream")
c.Status(fiber.StatusOK)
c.Send(storage.GetDefaultEngine())
return nil
2024-01-04 19:02:14 +00:00
}
return c.Status(400).JSON(aid.ErrorBadRequest)
}
func GetUserStorageFiles(c *fiber.Ctx) error {
return c.Status(200).JSON([]aid.JSON{})
}
func GetUserStorageFile(c *fiber.Ctx) error {
return c.Status(200).JSON(aid.JSON{})
}
func PutUserStorageFile(c *fiber.Ctx) error {
return c.Status(200).JSON(aid.JSON{})
}