mirror of
https://github.com/Lawin0129/LawinServer.git
synced 2026-01-13 02:42:22 +01:00
Change structure of LawinServer
This commit is contained in:
131
structure/cloudstorage.js
Normal file
131
structure/cloudstorage.js
Normal file
@@ -0,0 +1,131 @@
|
||||
const Express = require("express");
|
||||
const express = Express.Router();
|
||||
const crypto = require("crypto");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const functions = require("./functions.js");
|
||||
const memory = require("./../memory.json");
|
||||
|
||||
express.get("/fortnite/api/cloudstorage/system", async (req, res) => {
|
||||
functions.GetVersionInfo(req, memory);
|
||||
|
||||
if (memory.build >= 9.40 && memory.build <= 10.40) {
|
||||
return res.status(404).end();
|
||||
}
|
||||
|
||||
const dir = path.join(__dirname, "..", "CloudStorage")
|
||||
var CloudFiles = [];
|
||||
|
||||
fs.readdirSync(dir).forEach(name => {
|
||||
if (name.toLowerCase().endsWith(".ini")) {
|
||||
const ParsedFile = fs.readFileSync(path.join(dir, name), 'utf-8');
|
||||
const ParsedStats = fs.statSync(path.join(dir, name));
|
||||
|
||||
CloudFiles.push({
|
||||
"uniqueFilename": name,
|
||||
"filename": name,
|
||||
"hash": crypto.createHash('sha1').update(ParsedFile).digest('hex'),
|
||||
"hash256": crypto.createHash('sha256').update(ParsedFile).digest('hex'),
|
||||
"length": ParsedFile.length,
|
||||
"contentType": "application/octet-stream",
|
||||
"uploaded": ParsedStats.mtime,
|
||||
"storageType": "S3",
|
||||
"storageIds": {},
|
||||
"doNotCache": true
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
res.json(CloudFiles)
|
||||
})
|
||||
|
||||
express.get("/fortnite/api/cloudstorage/system/:file", async (req, res) => {
|
||||
const file = path.join(__dirname, "..", "CloudStorage", req.params.file);
|
||||
|
||||
if (fs.existsSync(file)) {
|
||||
const ParsedFile = fs.readFileSync(file);
|
||||
|
||||
return res.status(200).send(ParsedFile).end();
|
||||
} else {
|
||||
res.status(200);
|
||||
res.end();
|
||||
}
|
||||
})
|
||||
|
||||
express.get("/fortnite/api/cloudstorage/user/*/:file", async (req, res) => {
|
||||
if (!fs.existsSync(path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings"))) {
|
||||
fs.mkdirSync(path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings"));
|
||||
}
|
||||
|
||||
res.set("Content-Type", "application/octet-stream")
|
||||
|
||||
if (req.params.file.toLowerCase() != "clientsettings.sav") {
|
||||
return res.status(404).json({
|
||||
"error": "file not found"
|
||||
});
|
||||
}
|
||||
|
||||
functions.GetVersionInfo(req, memory);
|
||||
|
||||
var currentBuildID = memory.CL;
|
||||
const file = path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings", `ClientSettings-${currentBuildID}.Sav`);
|
||||
|
||||
if (fs.existsSync(file)) {
|
||||
const ParsedFile = fs.readFileSync(file);
|
||||
|
||||
return res.status(200).send(ParsedFile).end();
|
||||
} else {
|
||||
res.status(200);
|
||||
res.end();
|
||||
}
|
||||
})
|
||||
|
||||
express.get("/fortnite/api/cloudstorage/user/:accountId", async (req, res) => {
|
||||
if (!fs.existsSync(path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings"))) {
|
||||
fs.mkdirSync(path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings"));
|
||||
}
|
||||
|
||||
res.set("Content-Type", "application/json")
|
||||
|
||||
functions.GetVersionInfo(req, memory);
|
||||
|
||||
var currentBuildID = memory.CL;
|
||||
const file = path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings", `ClientSettings-${currentBuildID}.Sav`);
|
||||
|
||||
if (fs.existsSync(file)) {
|
||||
const ParsedFile = fs.readFileSync(file, 'utf-8');
|
||||
const ParsedStats = fs.statSync(file);
|
||||
|
||||
return res.json([{
|
||||
"uniqueFilename": "ClientSettings.Sav",
|
||||
"filename": "ClientSettings.Sav",
|
||||
"hash": crypto.createHash('sha1').update(ParsedFile).digest('hex'),
|
||||
"hash256": crypto.createHash('sha256').update(ParsedFile).digest('hex'),
|
||||
"length": Buffer.byteLength(ParsedFile),
|
||||
"contentType": "application/octet-stream",
|
||||
"uploaded": ParsedStats.mtime,
|
||||
"storageType": "S3",
|
||||
"storageIds": {},
|
||||
"accountId": req.params.accountId,
|
||||
"doNotCache": true
|
||||
}]);
|
||||
} else {
|
||||
return res.json([]);
|
||||
}
|
||||
})
|
||||
|
||||
express.put("/fortnite/api/cloudstorage/user/*/*", async (req, res) => {
|
||||
if (!fs.existsSync(path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings"))) {
|
||||
fs.mkdirSync(path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings"));
|
||||
}
|
||||
|
||||
functions.GetVersionInfo(req, memory);
|
||||
|
||||
var currentBuildID = memory.CL;
|
||||
const file = path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings", `ClientSettings-${currentBuildID}.Sav`);
|
||||
|
||||
fs.writeFileSync(file, req.rawBody, 'latin1');
|
||||
res.status(204).end();
|
||||
})
|
||||
|
||||
module.exports = express;
|
||||
Reference in New Issue
Block a user