Put the Revolution stuff in the repo

This commit is contained in:
BuildTools 2019-08-17 23:33:00 +01:00
commit 9f2cfc58c7
8 changed files with 163 additions and 0 deletions

5
.gitignore vendored Normal file
View file

@ -0,0 +1,5 @@
# Revolution stuff
.vscode
node_modules/
package-lock.json
config/config.json

View file

@ -0,0 +1,6 @@
{
"server": {
"port":5906,
"instance_type":"Default"
}
}

54
index.js Normal file
View file

@ -0,0 +1,54 @@
let dE = new Date();
var startTime = dE.getTime();
var endTime;
const express = require("express"),
app = express(),
randomstring = require("randomstring"),
fs = require("fs"),
chalk = require("chalk"),
busboy = require("connect-busboy");
const config = require("./config/config.json")
let modules = {};
console.clear();
fs.readFile('./misc/ascii.lol', function(err, data) {
if (err) {
throw err;
}
let asciiOut = data.toString()
.replace("|replaceVersion|", `${chalk.yellow("Version:")} ${chalk.cyan(internals.version)}`)
.replace("|titlecard|", chalk.yellow("The web server made for EUS"))
.replace("DEV", chalk.red("DEV")).replace("RELEASE", chalk.green("RELEASE"))
.replace("|replaceType|", `${chalk.yellow("Type: ")}${chalk.cyan(config.server.instance_type)}`);
console.log(asciiOut);
fs.readdir("./modules", (err, files) => {
for (var i = 0; i < files.length; i++) {
modules[files[i].toString().replace(".js", "")] = require(`./modules/${files[i].toString()}`);
console.log(`[Modules] Found module ${files[i].toString()}`)
}
modules.logger.log(internals.types.a, emoji.wave, "Starting Revolution...");
server();
});
});
const emoji = require("./misc/emoji_list.json");
const internals = {
version:"0.0.4 RELEASE",
instance:"Dev Instance", //Deprecated, does absolutely nothing.
types: {
a:"INFO",
b:"REQUEST",
c:"WARN"
}
}
function server() {
app.get('*', (req, res) => {
modules.request_handler.handle(modules, internals, emoji, req, res);
});
app.listen(config.server.port, () => {
dE = new Date();
endTime = dE.getTime();
modules.logger.log(internals.types.a, emoji.thumb_up, `Started Revolution on port ${config.server.port}! Took ${endTime - startTime}ms`);
});
}

6
misc/ascii.lol Normal file
View file

@ -0,0 +1,6 @@
____ __ __ _
/ __ \___ _ ______ / /_ __/ /_(_)___ ____ |titlecard|
/ /_/ / _ \ | / / __ \/ / / / / __/ / __ \/ __ \ |replaceVersion|
/ _, _/ __/ |/ / /_/ / / /_/ / /_/ / /_/ / / / /
/_/ |_|\___/|___/\____/_/\__,_/\__/_/\____/_/ /_/ |replaceType|
--------------------------------------------------------------------------------

9
misc/emoji_list.json Normal file
View file

@ -0,0 +1,9 @@
{
"wave":"👋",
"thumb_up":"👍",
"page":"📄",
"dizzy":"😵",
"heavy_check":"✔️",
"folder":"📁",
"fast_up":"⏫"
}

37
modules/logger.js Normal file
View file

@ -0,0 +1,37 @@
"use strict";
const fs = require("fs");
const chalk = require("chalk");
let d = new Date();
module.exports = {
log: function(type, emoji, text) {
d = new Date();
console.log(`${chalk.green(`[${timeNumbers(d.getHours())}:${timeNumbers(d.getMinutes())}:${timeNumbers(d.getSeconds())} - ${type}]`)} ${emoji} ${text}`)
}
}
function timeNumbers(inp) {
if (inp == 0) {
return "00";
} else if (inp == 1) {
return "01";
} else if (inp == 2) {
return "02";
} else if (inp == 3) {
return "03";
} else if (inp == 4) {
return "04";
} else if (inp == 5) {
return "05";
} else if (inp == 6) {
return "06";
} else if (inp == 7) {
return "07";
} else if (inp == 8) {
return "08";
} else if (inp == 9) {
return "09";
} else {
return inp;
}
}

View file

@ -0,0 +1,25 @@
const fs = require("fs");
module.exports = {
handle:function(modules, internals, emoji, req, res) {
/*
req - Request from client
res - Response from server
*/
res.set("Server-Type", "Revolution");
if (req.url == "/") {
modules.logger.log(`${internals.types.b}: ${req.method}`, emoji.page, `${req.url} was requested`);
res.end(); // Send a blank response, this can be changed to make it do whatever.
} else {
fs.access(__dirname + req.url, fs.constants.F_OK | fs.constants.W_OK, (err) => {
if (err) {
modules.logger.log(`${internals.types.b}: ${req.method}`, emoji.page, `${req.url} was requested - Returned 404`);
res.status(404).send("404!<hr>Revolution");
} else {
modules.logger.log(`${internals.types.b}: ${req.method}`, emoji.page, `${req.url} was requested`);
res.sendFile(__dirname + req.url);
}
});
}
}
}

21
package.json Normal file
View file

@ -0,0 +1,21 @@
{
"name": "neweus",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"chalk": "^2.4.2",
"connect-busboy": "0.0.2",
"express": "^4.17.1",
"get-folder-size": "^2.0.1",
"http": "0.0.0",
"randomstring": "^1.1.5",
"request": "^2.88.0",
"semantic-ui": "^2.4.2"
}
}