-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewKey.js
35 lines (28 loc) · 844 Bytes
/
newKey.js
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
const fs = require("fs");
let [nodePath, appPath, length] = process.argv;
let characterSet =
"1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
let targetLength = length ?? 255;
let newKey = "";
for (let index = 0; index < targetLength; index++) {
newKey += characterSet.substr(
Math.floor(Math.random() * characterSet.length),
1
);
}
console.log(`New Key is: ${newKey}`);
try {
fs.statSync("./config.json");
} catch (error) {
fs.copyFileSync("./config.template.json", "./config.json");
}
try {
let config = JSON.parse(fs.readFileSync("./config.json").toString());
config.apiKeys.push(newKey);
fs.writeFileSync("./config.json", JSON.stringify(config));
console.log("Added to config");
} catch (error) {
console.error(
`There was an issue adding the new key to config.json\n${error}`
);
}