-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
95 lines (83 loc) · 2.67 KB
/
index.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const Express = require("express");
const DB = require("./db");
const config = global.config = require("./config");
const ejs = require("ejs");
const fs = require("fs");
const app = Express();
if (!fs.existsSync("./db/")) {
if (fs.existsSync("./db.json")) {
console.error(`
_____ _______ ____ _____ _
/ ____|__ __/ __ \\| __ \\| |
| (___ | | | | | | |__) | |
\\___ \\ | | | | | | ___/| |
____) | | | | |__| | | |_|
|_____/ |_| \\____/|_| (_)
UltraShare has detected a legacy 1.x database in the current folder. Please follow the migration steps before continuing!`);
process.exit();
}
fs.mkdirSync("./db");
}
if (!fs.existsSync("./files/")) fs.mkdirSync("./files");
global.fileDB = new DB("./db/files.json");
global.apiKeyDB = new DB("./db/apikeys.json");
global.userDB = new DB("./db/users.json");
require("./http/api")(app);
require("./http/admin")(app);
app.get("/", (req, res) => {
console.log("[MAIN]", req.ip, req.url, req.header("User-Agent"));
ejs.renderFile("./http/dynamic/hero.ejs", {
pageTitle: "UltraShare",
heroType: "primary is-bold",
heroTitle: "Welcome to " + config.instanceName + "!",
heroText: config.instanceDescription,
heroLinks: [
{
color: "link is-large",
icon: "account_circle",
text: "Login",
link: "/login.html"
},
{
color: "primary is-large",
icon: "admin_panel_settings",
text: "Administrator Login",
link: "/dash/admin"
}
]
}, {}, (err, str) => {
if (err) { throw err; }
res.send(str);
});
});
app.use(Express.static("http/staticFiles"));
require("./http/db")(app);
app.get("/*", (req, res) => {
console.log("[404]", req.ip, req.url, req.header("User-Agent"));
res.status(404);
ejs.renderFile("./http/dynamic/hero.ejs", {
pageTitle: "404 - Not found",
heroType: "danger is-bold",
heroTitle: "<kbd>404</kbd>",
heroText: `The file at the URL <kbd>${req.url}</kbd> could not be found.`,
heroLinks: [
{
color: "link is-large",
icon: "arrow_back",
text: "",
link: "javascript:window.history.back()"
},
{
color: "link is-large",
icon: "home",
text: "",
link: "/"
}
]
}, {}, (err, str) => {
if (err) { throw err; }
res.send(str);
});
});
app.listen(config.port);
console.log(`[HTTP] Ready on port ${config.port}!`);