mirror of
https://github.com/Lawin0129/LawinServer.git
synced 2026-01-13 02:42:22 +01:00
Fixed formatting in cloudstorage.js
This commit is contained in:
@@ -7,56 +7,51 @@ const functions = require("./functions.js");
|
|||||||
|
|
||||||
express.use((req, res, next) => {
|
express.use((req, res, next) => {
|
||||||
// Get raw body in encoding latin1 for ClientSettings
|
// Get raw body in encoding latin1 for ClientSettings
|
||||||
if (
|
if (req.originalUrl.toLowerCase().startsWith("/fortnite/api/cloudstorage/user/") && req.method == "PUT") {
|
||||||
req.originalUrl
|
|
||||||
.toLowerCase()
|
|
||||||
.startsWith("/fortnite/api/cloudstorage/user/") &&
|
|
||||||
req.method == "PUT"
|
|
||||||
) {
|
|
||||||
req.rawBody = "";
|
req.rawBody = "";
|
||||||
req.setEncoding("latin1");
|
req.setEncoding("latin1");
|
||||||
|
|
||||||
req.on("data", (chunk) => (req.rawBody += chunk));
|
req.on("data", (chunk) => req.rawBody += chunk);
|
||||||
req.on("end", () => next());
|
req.on("end", () => next());
|
||||||
} else return next();
|
}
|
||||||
});
|
else return next();
|
||||||
|
})
|
||||||
|
|
||||||
express.get("/fortnite/api/cloudstorage/system", async (req, res) => {
|
express.get("/fortnite/api/cloudstorage/system", async (req, res) => {
|
||||||
const memory = functions.GetVersionInfo(req);
|
const memory = functions.GetVersionInfo(req);
|
||||||
|
|
||||||
if (memory.build >= 9.4 && memory.build <= 10.4) {
|
if (memory.build >= 9.40 && memory.build <= 10.40) {
|
||||||
return res.status(404).end();
|
return res.status(404).end();
|
||||||
}
|
}
|
||||||
|
|
||||||
const dir = path.join(__dirname, "..", "CloudStorage");
|
const dir = path.join(__dirname, "..", "CloudStorage")
|
||||||
var CloudFiles = [];
|
var CloudFiles = [];
|
||||||
|
|
||||||
fs.readdirSync(dir).forEach((name) => {
|
fs.readdirSync(dir).forEach(name => {
|
||||||
if (name.toLowerCase().endsWith(".ini")) {
|
if (name.toLowerCase().endsWith(".ini")) {
|
||||||
const ParsedFile = fs.readFileSync(path.join(dir, name), "utf-8");
|
const ParsedFile = fs.readFileSync(path.join(dir, name), 'utf-8');
|
||||||
const ParsedStats = fs.statSync(path.join(dir, name));
|
const ParsedStats = fs.statSync(path.join(dir, name));
|
||||||
|
|
||||||
CloudFiles.push({
|
CloudFiles.push({
|
||||||
uniqueFilename: name,
|
"uniqueFilename": name,
|
||||||
filename: name,
|
"filename": name,
|
||||||
hash: crypto.createHash("sha1").update(ParsedFile).digest("hex"),
|
"hash": crypto.createHash('sha1').update(ParsedFile).digest('hex'),
|
||||||
hash256: crypto.createHash("sha256").update(ParsedFile).digest("hex"),
|
"hash256": crypto.createHash('sha256').update(ParsedFile).digest('hex'),
|
||||||
length: ParsedFile.length,
|
"length": ParsedFile.length,
|
||||||
contentType: "application/octet-stream",
|
"contentType": "application/octet-stream",
|
||||||
uploaded: ParsedStats.mtime,
|
"uploaded": ParsedStats.mtime,
|
||||||
storageType: "S3",
|
"storageType": "S3",
|
||||||
storageIds: {},
|
"storageIds": {},
|
||||||
doNotCache: true,
|
"doNotCache": true
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
res.json(CloudFiles);
|
res.json(CloudFiles)
|
||||||
});
|
})
|
||||||
|
|
||||||
express.get("/fortnite/api/cloudstorage/system/:file", async (req, res) => {
|
express.get("/fortnite/api/cloudstorage/system/:file", async (req, res) => {
|
||||||
const memory = functions.GetVersionInfo(req);
|
const memory = functions.GetVersionInfo(req);
|
||||||
|
|
||||||
const file = path.join(__dirname, "..", "CloudStorage", req.params.file);
|
const file = path.join(__dirname, "..", "CloudStorage", req.params.file);
|
||||||
|
|
||||||
if (fs.existsSync(file)) {
|
if (fs.existsSync(file)) {
|
||||||
@@ -72,26 +67,20 @@ express.get("/fortnite/api/cloudstorage/system/:file", async (req, res) => {
|
|||||||
res.status(200);
|
res.status(200);
|
||||||
res.end();
|
res.end();
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
express.get("/fortnite/api/cloudstorage/user/*/:file", async (req, res) => {
|
express.get("/fortnite/api/cloudstorage/user/*/:file", async (req, res) => {
|
||||||
try {
|
try {
|
||||||
if (
|
if (!fs.existsSync(path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings"))) {
|
||||||
!fs.existsSync(
|
fs.mkdirSync(path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings"));
|
||||||
path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings")
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
fs.mkdirSync(
|
|
||||||
path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
|
|
||||||
res.set("Content-Type", "application/octet-stream");
|
res.set("Content-Type", "application/octet-stream")
|
||||||
|
|
||||||
if (req.params.file.toLowerCase() != "clientsettings.sav") {
|
if (req.params.file.toLowerCase() != "clientsettings.sav") {
|
||||||
return res.status(404).json({
|
return res.status(404).json({
|
||||||
error: "file not found",
|
"error": "file not found"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,20 +89,8 @@ express.get("/fortnite/api/cloudstorage/user/*/:file", async (req, res) => {
|
|||||||
var currentBuildID = memory.CL;
|
var currentBuildID = memory.CL;
|
||||||
|
|
||||||
let file;
|
let file;
|
||||||
if (process.env.LOCALAPPDATA)
|
if (process.env.LOCALAPPDATA) file = path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings", `ClientSettings-${currentBuildID}.Sav`);
|
||||||
file = path.join(
|
else file = path.join(__dirname, "..", "ClientSettings", `ClientSettings-${currentBuildID}.Sav`);
|
||||||
process.env.LOCALAPPDATA,
|
|
||||||
"LawinServer",
|
|
||||||
"ClientSettings",
|
|
||||||
`ClientSettings-${currentBuildID}.Sav`
|
|
||||||
);
|
|
||||||
else
|
|
||||||
file = path.join(
|
|
||||||
__dirname,
|
|
||||||
"..",
|
|
||||||
"ClientSettings",
|
|
||||||
`ClientSettings-${currentBuildID}.Sav`
|
|
||||||
);
|
|
||||||
|
|
||||||
if (fs.existsSync(file)) {
|
if (fs.existsSync(file)) {
|
||||||
const ParsedFile = fs.readFileSync(file);
|
const ParsedFile = fs.readFileSync(file);
|
||||||
@@ -123,83 +100,57 @@ express.get("/fortnite/api/cloudstorage/user/*/:file", async (req, res) => {
|
|||||||
res.status(200);
|
res.status(200);
|
||||||
res.end();
|
res.end();
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
express.get("/fortnite/api/cloudstorage/user/:accountId", async (req, res) => {
|
express.get("/fortnite/api/cloudstorage/user/:accountId", async (req, res) => {
|
||||||
try {
|
try {
|
||||||
if (
|
if (!fs.existsSync(path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings"))) {
|
||||||
!fs.existsSync(
|
fs.mkdirSync(path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings"));
|
||||||
path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings")
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
fs.mkdirSync(
|
|
||||||
path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
|
|
||||||
res.set("Content-Type", "application/json");
|
res.set("Content-Type", "application/json")
|
||||||
|
|
||||||
const memory = functions.GetVersionInfo(req);
|
const memory = functions.GetVersionInfo(req);
|
||||||
|
|
||||||
var currentBuildID = memory.CL;
|
var currentBuildID = memory.CL;
|
||||||
|
|
||||||
let file;
|
let file;
|
||||||
if (process.env.LOCALAPPDATA)
|
if (process.env.LOCALAPPDATA) file = path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings", `ClientSettings-${currentBuildID}.Sav`);
|
||||||
file = path.join(
|
else file = path.join(__dirname, "..", "ClientSettings", `ClientSettings-${currentBuildID}.Sav`);
|
||||||
process.env.LOCALAPPDATA,
|
|
||||||
"LawinServer",
|
|
||||||
"ClientSettings",
|
|
||||||
`ClientSettings-${currentBuildID}.Sav`
|
|
||||||
);
|
|
||||||
else
|
|
||||||
file = path.join(
|
|
||||||
__dirname,
|
|
||||||
"..",
|
|
||||||
"ClientSettings",
|
|
||||||
`ClientSettings-${currentBuildID}.Sav`
|
|
||||||
);
|
|
||||||
|
|
||||||
if (fs.existsSync(file)) {
|
if (fs.existsSync(file)) {
|
||||||
const ParsedFile = fs.readFileSync(file, "latin1");
|
const ParsedFile = fs.readFileSync(file, 'latin1');
|
||||||
const ParsedStats = fs.statSync(file);
|
const ParsedStats = fs.statSync(file);
|
||||||
|
|
||||||
return res.json([
|
return res.json([{
|
||||||
{
|
"uniqueFilename": "ClientSettings.Sav",
|
||||||
uniqueFilename: "ClientSettings.Sav",
|
"filename": "ClientSettings.Sav",
|
||||||
filename: "ClientSettings.Sav",
|
"hash": crypto.createHash('sha1').update(ParsedFile).digest('hex'),
|
||||||
hash: crypto.createHash("sha1").update(ParsedFile).digest("hex"),
|
"hash256": crypto.createHash('sha256').update(ParsedFile).digest('hex'),
|
||||||
hash256: crypto.createHash("sha256").update(ParsedFile).digest("hex"),
|
"length": Buffer.byteLength(ParsedFile),
|
||||||
length: Buffer.byteLength(ParsedFile),
|
"contentType": "application/octet-stream",
|
||||||
contentType: "application/octet-stream",
|
"uploaded": ParsedStats.mtime,
|
||||||
uploaded: ParsedStats.mtime,
|
"storageType": "S3",
|
||||||
storageType: "S3",
|
"storageIds": {},
|
||||||
storageIds: {},
|
"accountId": req.params.accountId,
|
||||||
accountId: req.params.accountId,
|
"doNotCache": true
|
||||||
doNotCache: true,
|
}]);
|
||||||
},
|
|
||||||
]);
|
|
||||||
} else {
|
} else {
|
||||||
return res.json([]);
|
return res.json([]);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
express.put("/fortnite/api/cloudstorage/user/*/:file", async (req, res) => {
|
express.put("/fortnite/api/cloudstorage/user/*/:file", async (req, res) => {
|
||||||
try {
|
try {
|
||||||
if (
|
if (!fs.existsSync(path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings"))) {
|
||||||
!fs.existsSync(
|
fs.mkdirSync(path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings"));
|
||||||
path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings")
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
fs.mkdirSync(
|
|
||||||
path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
|
|
||||||
if (req.params.file.toLowerCase() != "clientsettings.sav") {
|
if (req.params.file.toLowerCase() != "clientsettings.sav") {
|
||||||
return res.status(404).json({
|
return res.status(404).json({
|
||||||
error: "file not found",
|
"error": "file not found"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,23 +159,11 @@ express.put("/fortnite/api/cloudstorage/user/*/:file", async (req, res) => {
|
|||||||
var currentBuildID = memory.CL;
|
var currentBuildID = memory.CL;
|
||||||
|
|
||||||
let file;
|
let file;
|
||||||
if (process.env.LOCALAPPDATA)
|
if (process.env.LOCALAPPDATA) file = path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings", `ClientSettings-${currentBuildID}.Sav`);
|
||||||
file = path.join(
|
else file = path.join(__dirname, "..", "ClientSettings", `ClientSettings-${currentBuildID}.Sav`);
|
||||||
process.env.LOCALAPPDATA,
|
|
||||||
"LawinServer",
|
|
||||||
"ClientSettings",
|
|
||||||
`ClientSettings-${currentBuildID}.Sav`
|
|
||||||
);
|
|
||||||
else
|
|
||||||
file = path.join(
|
|
||||||
__dirname,
|
|
||||||
"..",
|
|
||||||
"ClientSettings",
|
|
||||||
`ClientSettings-${currentBuildID}.Sav`
|
|
||||||
);
|
|
||||||
|
|
||||||
fs.writeFileSync(file, req.rawBody, "latin1");
|
fs.writeFileSync(file, req.rawBody, 'latin1');
|
||||||
res.status(204).end();
|
res.status(204).end();
|
||||||
});
|
})
|
||||||
|
|
||||||
module.exports = express;
|
module.exports = express;
|
||||||
|
|||||||
Reference in New Issue
Block a user