diff --git a/config/config.example.json b/config/config.example.json deleted file mode 100644 index 02991ef..0000000 --- a/config/config.example.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "server": { - "port":8080, - "image_dir":"./i/", - "export_uri":"This url is used to return to the user when an image is uploaded e.g http://localhost:8080/", - "instance_type":"Github Open Release", - "acceptedTypes":[ - ".png", - ".jpg", - ".jpeg", - ".gif" - ] - } -} \ No newline at end of file diff --git a/files/index.html b/files/index.html deleted file mode 100644 index 3e3c70c..0000000 --- a/files/index.html +++ /dev/null @@ -1,33 +0,0 @@ - - - EUS - Default Page - - - - - - \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index d7f1ab2..0000000 --- a/index.js +++ /dev/null @@ -1,108 +0,0 @@ -const express = require("express"), app = express(), config = require("./config/config.json"), emoji = require("./misc/emoji_list.json"), randomstring = require("randomstring"), fs = require("fs"), chalk = require("chalk"), busboy = require("connect-busboy"), dirname = __dirname+"/"; -internals = { - version:"0.0.5 Open", - types: { - a:"INFO", - b:"REQUEST", - c:"WARN" - } -}; -let dE = new Date(), startTime = dE.getTime(), endTime, modules = [], image_json; - -// Clear console before printing anything -console.clear(); - -fs.readFile('./misc/ascii.txt', function(err, data) { - if (err) throw err; - fs.readdir(config.server.image_dir, (err, files) => { - // Generate the banner - 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)}`) - .replace("|replaceStats|", `${chalk.yellow("Images: ")}${chalk.cyan(files.length)}`); - // Print the banner - console.log(asciiOut); - // Get the modules from the ./modules folder - fs.readdir("./modules", (err, files) => { - if (err) throw err; - for (var i = 0; i < files.length; i++) { - /* - For every file in the array, output that it was found - in the console and attempt to load it using require. - Oh, and check that it has .js in it's file name! - */ - if (files[i].includes(".js")) { - modules[files[i].toString().replace(".js", "")] = require(`./modules/${files[i].toString()}`); - console.log(`[Modules] Found module ${files[i].toString()}`); - } else { - console.log(`[Modules] Found file ${files[i]}. It is not a module.`) - } - } - fs.access("./image-type.json", error => { - if (error) { - fs.writeFile('./image-type.json', '{\n\}', function(err) { - if (err) throw err; - modules.logger.log(internals.types.a, emoji.heavy_check, "Created image-type File!"); - image_json = require("./image-type.json"); - }); - } else { - image_json = require("./image-type.json"); - } - }); - fs.access(config.server.image_dir, error => { - if (error) { - fs.mkdirSync(config.server.image_dir); - } - }); - modules.logger.log(internals.types.a, emoji.wave, "Starting Revolution..."); - server(); - }); - }); -}); - -// File name that is returned to the uploader -let fileOutName; - -function server() { - app.use(busboy()); - app.route('/upload') - .post(function (req, res, next) { - dE = new Date(); startTime = dE.getTime(); - var fstream; - var thefe; - req.pipe(req.busboy); - req.busboy.on('file', function (fieldname, file, filename) { - image_json = require("./image-type.json"); - fileOutName = randomstring.generate(14); - modules.logger.log(`${internals.types.b}: ${req.method}`, emoji.fast_up, `Upload of ${fileOutName} started.`); - if (config.server.acceptedTypes.includes(`.${filename.split(".")[filename.split(".").length-1]}`)) { - thefe = `.${filename.split(".")[filename.split(".").length-1]}`; - } else { - res.end("This file type isn't accepted currently."); - return; - } - //Path where image will be uploaded - fstream = fs.createWriteStream(__dirname + '/i/' + fileOutName + thefe); - file.pipe(fstream); - fstream.on('close', function () { - dE = new Date(); - endTime = dE.getTime(); - image_json[fileOutName] = `.${filename.split(".")[filename.split(".").length-1]}`; - fs.writeFile('./image-type.json', JSON.stringify(image_json), function(err) { - if (err) throw err; - modules.logger.log(`${internals.types.b}: ${req.method}`, emoji.heavy_check, ` Upload of ${fileOutName} finished. Took ${endTime - startTime}ms`); - res.end(config.server.export_uri+""+fileOutName); - }); - }); - }); - }) - .get(function (req, res, next) { - res.status(405).send("405! You requested the \"/upload\" endpoint with method \"GET\" but it was expecting POST
Revolution - A web server designed for EUS") - }); - app.get('*', (req, res) => { modules.request_handler.handle(modules.logger, image_json, internals, emoji, config, fs, chalk, req, res, dirname); }); - 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.txt b/misc/ascii.txt deleted file mode 100644 index 1f3b946..0000000 --- a/misc/ascii.txt +++ /dev/null @@ -1,6 +0,0 @@ - ____ __ __ _ - / __ \___ _ ______ / /_ __/ /_(_)___ ____ |titlecard| - / /_/ / _ \ | / / __ \/ / / / / __/ / __ \/ __ \ |replaceVersion| - / _, _/ __/ |/ / /_/ / / /_/ / /_/ / /_/ / / / / |replaceStats| -/_/ |_|\___/|___/\____/_/\__,_/\__/_/\____/_/ /_/ |replaceType| --------------------------------------------------------------------------------- \ No newline at end of file diff --git a/misc/emoji_list.json b/misc/emoji_list.json deleted file mode 100644 index e330c85..0000000 --- a/misc/emoji_list.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "wave":"👋", - "thumb_up":"👍", - "page":"📄", - "dizzy":"😵", - "heavy_check":"✔️", - "folder":"📁", - "fast_up":"⏫", - "cross":"❌" -} \ No newline at end of file diff --git a/modules/logger.js b/modules/logger.js deleted file mode 100644 index d1da0cd..0000000 --- a/modules/logger.js +++ /dev/null @@ -1,19 +0,0 @@ -"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 <= 9) { - return "0"+inp; - } else { - return inp; - } -} \ No newline at end of file diff --git a/modules/request_handler.js b/modules/request_handler.js deleted file mode 100644 index 3ded021..0000000 --- a/modules/request_handler.js +++ /dev/null @@ -1,50 +0,0 @@ -"use strict"; -let d = new Date(), -startTime, -endTime, -filesC; - -module.exports = { - handle: function(logger, image_json, internals, emoji, config, fs, chalk, req, res, dirname) { - d = new Date(); - startTime = d.getTime(); - res.set('Server-Type', 'Revolution EUS'); - if (req.url == "/" || req.url == "/index.html") { - fs.readFile('./files/index.html', function(err, data) { - if (err) throw err; - fs.readdir(dirname+"i/", (err, files) => { - if (err) throw err; - filesC = data.toString().replace("|replaceVersion|", internals.version).replace("|replaceInstance|", config.server.instance_type); - res.send(filesC); - d = new Date(); - endTime = d.getTime(); - logger.log(`${internals.types.b}: ${req.method}`, emoji.page, `${req.ip} | ${chalk.green("[200]")} ${req.url} ${endTime - startTime}ms`) - }); - }); - } else { - let urs = ""+req.url; urs = urs.split("/")[1]; - fs.access(config.server.image_dir+urs+image_json[urs], error => { - if (error) { - fs.access("./files"+req.url, error => { - if (error) { - res.status(404).end("404!"); - d = new Date(); - endTime = d.getTime(); - logger.log(`${internals.types.b}: ${req.method}`, emoji.cross, `${req.ip} | ${chalk.red("[404]")} ${req.url} ${endTime - startTime}ms`); - } else { - res.sendFile(dirname+"files"+req.url); - d = new Date(); - endTime = d.getTime(); - logger.log(`${internals.types.b}: ${req.method}`, emoji.heavy_check, `${req.ip} | ${chalk.green("[200]")} ${req.url} ${endTime - startTime}ms`); - } - }); - } else { - res.sendFile(dirname+"i/"+urs+image_json[urs]); - d = new Date(); - endTime = d.getTime(); - logger.log(`${internals.types.b}: ${req.method}`, emoji.heavy_check, `${req.ip} | ${chalk.green("[200]")} ${req.url} ${endTime - startTime}ms`); - } - }); - } - } -} \ No newline at end of file diff --git a/package.json b/package.json deleted file mode 100644 index 795af66..0000000 --- a/package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "neweus", - "version": "0.0.5", - "description": "", - "main": "index.js", - "author": "", - "license": "ISC", - "dependencies": { - "chalk": "^2.4.2", - "connect-busboy": "0.0.2", - "express": "^4.17.1", - "http": "0.0.0", - "randomstring": "^1.1.5" - } -}