forked from HybridFNBR/Neonite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
99 lines (85 loc) · 3.23 KB
/
app.js
File metadata and controls
99 lines (85 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const sails = require("sails");
const NeoLog = require("./structs/NeoLog");
const { extractEmbeddedFiles } = require("./structs/Extractor");
const { default: axios } = require("axios");
const fs = require("fs");
const path = require("path");
const ini = require("ini");
const { externalDir, bundledDir, isPackaged } = require("./structs/paths");
//etract embedded files on first run, func checks if its needed
extractEmbeddedFiles();
const sailsAppPath = isPackaged ? __dirname : process.cwd();
const configPath = path.join(externalDir, "config.ini");
const keychainPath = path.join(externalDir, "responses", "keychain.json");
const config = ini.parse(fs.readFileSync(configPath, "utf-8"));
const responsesDir = path.join(externalDir, "responses");
if (!fs.existsSync(responsesDir)) {
fs.mkdirSync(responsesDir, { recursive: true });
}
let keychain;
if (fs.existsSync(keychainPath)) {
keychain = JSON.parse(fs.readFileSync(keychainPath, "utf-8"));
} else {
keychain = [];
}
async function compareAndUpdateKeychain() {
const response = await axios.get('https://fortnitecentral.genxgames.gg/api/v1/aes', {validateStatus: () => true});
if (response.status === 200) {
const data = response.data;
let missingCount = 0;
const keychainArray = [];
for (const keys of data.dynamicKeys) {
if (!keychain.includes(keys.keychain)) {
missingCount++;
keychainArray.push(keys.keychain);
}
}
keychain.push(...keychainArray);
fs.writeFileSync(keychainPath, JSON.stringify(keychain, null, 2));
NeoLog.Debug(`Fetched ${missingCount} New Keychains from Fortnite Central.`);
}
else if (response.status !== 200) {
NeoLog.warn("Fortnite Central is down, falling back to dillyapis for the keychain");
const fallbackResponse = await axios.get('https://export-service.dillyapis.com/v1/aes', {validateStatus: () => true});
if (fallbackResponse.status === 200) {
const data = fallbackResponse.data
let missingCount = 0;
const keychainArray = [];
for (const keys of data.dynamicKeys) {
if (!keychain.includes(keys.keychain)) {
missingCount++;
keychainArray.push(keys.keychain);
}
}
keychain.push(...keychainArray);
fs.writeFileSync(keychainPath, JSON.stringify(keychain, null, 2));
NeoLog.Debug(`Fetched ${missingCount} New Keychains From dillyapis`);
}
else
{
NeoLog.Error("Unable to connect to both Fortnite Central and dillyapis! Falling back to existing keychains on your local disk. You may experience issues!");
}
}
}
async function startBackend() {
sails.lift({
appPath: sailsAppPath, //tell sails where it should look for the files
port: 5595,
environment: "production",
hooks: {
session: false
},
log: {
level: config.logLevel
},
}, (err) => {
if (err) {
console.error(err);
}
});
}
async function runFunctions() {
await compareAndUpdateKeychain();
await startBackend();
}
runFunctions();