From 9f2cfc58c751b24eaf64605ef9c2d84c14a4ab73 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 17 Aug 2019 23:33:00 +0100 Subject: [PATCH] Put the Revolution stuff in the repo --- .gitignore | 5 ++++ config/config.example.json | 6 +++++ index.js | 54 ++++++++++++++++++++++++++++++++++++++ misc/ascii.lol | 6 +++++ misc/emoji_list.json | 9 +++++++ modules/logger.js | 37 ++++++++++++++++++++++++++ modules/request_handler.js | 25 ++++++++++++++++++ package.json | 21 +++++++++++++++ 8 files changed, 163 insertions(+) create mode 100644 .gitignore create mode 100644 config/config.example.json create mode 100644 index.js create mode 100644 misc/ascii.lol create mode 100644 misc/emoji_list.json create mode 100644 modules/logger.js create mode 100644 modules/request_handler.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bf6937a --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +# Revolution stuff +.vscode +node_modules/ +package-lock.json +config/config.json diff --git a/config/config.example.json b/config/config.example.json new file mode 100644 index 0000000..8246c73 --- /dev/null +++ b/config/config.example.json @@ -0,0 +1,6 @@ +{ + "server": { + "port":5906, + "instance_type":"Default" + } +} \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..24cd96d --- /dev/null +++ b/index.js @@ -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`); + }); +} \ No newline at end of file diff --git a/misc/ascii.lol b/misc/ascii.lol new file mode 100644 index 0000000..37f62d5 --- /dev/null +++ b/misc/ascii.lol @@ -0,0 +1,6 @@ + ____ __ __ _ + / __ \___ _ ______ / /_ __/ /_(_)___ ____ |titlecard| + / /_/ / _ \ | / / __ \/ / / / / __/ / __ \/ __ \ |replaceVersion| + / _, _/ __/ |/ / /_/ / / /_/ / /_/ / /_/ / / / / +/_/ |_|\___/|___/\____/_/\__,_/\__/_/\____/_/ /_/ |replaceType| +-------------------------------------------------------------------------------- \ No newline at end of file diff --git a/misc/emoji_list.json b/misc/emoji_list.json new file mode 100644 index 0000000..be4a260 --- /dev/null +++ b/misc/emoji_list.json @@ -0,0 +1,9 @@ +{ + "wave":"👋", + "thumb_up":"👍", + "page":"📄", + "dizzy":"😵", + "heavy_check":"✔️", + "folder":"📁", + "fast_up":"⏫" +} \ No newline at end of file diff --git a/modules/logger.js b/modules/logger.js new file mode 100644 index 0000000..7aede69 --- /dev/null +++ b/modules/logger.js @@ -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; + } +} \ No newline at end of file diff --git a/modules/request_handler.js b/modules/request_handler.js new file mode 100644 index 0000000..7d77993 --- /dev/null +++ b/modules/request_handler.js @@ -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!
Revolution"); + } else { + modules.logger.log(`${internals.types.b}: ${req.method}`, emoji.page, `${req.url} was requested`); + res.sendFile(__dirname + req.url); + } + }); + } + } +} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..e39c28d --- /dev/null +++ b/package.json @@ -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" + } +}