-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
setup.js
81 lines (71 loc) · 2.9 KB
/
setup.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
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
const util = require("./util")
const fs = require('fs');
if (process.argv.includes("migrate")) {
console.log("This will migrate a UltraShare 1.x DB to an UltraShare 2.0 DB");
console.log("Make sure UltraShare is not running!");
console.log("starting in 10 seconds");
console.log("updating config.js (comments will be lost, sorry)");
let oldConfig = require("./config");
if (oldConfig.adminSecret) {
console.error("The config has already been migrated, quitting!")
process.exit();
}
var adminSecret = util.randomString(32, "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_")
console.log("Remember this: Your admin secret is", adminSecret)
let newConfig = {
port: oldConfig.port,
adminSecret,
instanceName: "UltraShare",
instanceDescription: "UltraShare is a all in one server for screenshots, files, images, and links.",
fileName: oldConfig.fileName
};
fs.renameSync("./config.js", "config.old.js")
fs.writeFileSync("./config.js", "module.exports = " + JSON.stringify(newConfig, null, 4))
console.log("Wrote new config")
fs.mkdirSync("./db")
console.log('Creating users DB')
fs.writeFileSync("./db/users.json", JSON.stringify([{
"user": oldConfig.username,
"totpSecret": oldConfig.totpSecret
}]))
console.log("Creating API keys DB")
fs.writeFileSync("./db/apiKeys.json", JSON.stringify([{
"id": "original",
"key": oldConfig.apiKey,
"user": oldConfig.username,
"name": "API Key",
"creator": "UltraShare Migration",
"fileDelete": true,
"fileModify": true,
"fileCreate": true,
"fileList": true,
"accountManage": true,
"createdAt": new Date(),
"lastUsedAt": new Date()
}]))
console.log("Updating files database")
var files = require("./db.json")
files.map((f) => f.user = oldConfig.username)
fs.writeFileSync("./db/files.json",JSON.stringify(files))
console.log("Done!")
} else if (process.argv.includes("setup")) {
if (fs.existsSync("./config.js")) {
console.error("The config already exists, quitting!")
process.exit();
}
var adminSecret = util.randomString(32, "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_")
console.log("Remember this: Your admin secret is", adminSecret)
let newConfig = {
"port": 8082,
"adminSecret": adminSecret,
"instanceName": "UltraShare",
"instanceDescription": "UltraShare is a all in one server for screenshots, files, images, and links.",
"fileName": {
"length": 3,
"allowedChars": "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_"
}
}
fs.writeFileSync("./config.js", "module.exports = " + JSON.stringify(newConfig, null, 4))
console.log("Wrote new config")
fs.mkdirSync("./db");
}