const express = require("express"), fs = require("fs"), path = require("path"), multer = require("multer"), bodyParser = require("body-parser") var app = express() var uploads = multer({ storage: multer.memoryStorage() }) var PORT = process.env.PORT || 8080 var directory = process.env.FILES_DIR var passwd = process.env.PASSWORD var baseHTML = fs.readFileSync(path.join(__dirname, 'resources/base.html')).toString() var baseStart = baseHTML.substring(0, baseHTML.indexOf('{CONTENT}')) var baseEnd = baseHTML.substring(baseHTML.indexOf('{CONTENT}') + 9, baseHTML.length) if (!directory) { console.error("No directory specified! Please specify one using the environment variable FILES_DIR.") return } app.use('/b', express.static(directory)) app.use(express.static(path.join(__dirname, 'static'))) app.use(bodyParser.urlencoded({ extended: false })) app.listen(PORT, () => { console.log("Now listening on PORT: " + PORT) if (!passwd) { console.log("Password variable not found. Uploading from site is not available.") } else { console.log("Password variable found! Uploads are now available on the site.") } }) app.get("/b*", (req, res) => { var file = req.params[0] var absPath = path.join(directory, file) res.setHeader('Content-Type', 'text/html') try { var dirContents = fs.readdirSync(absPath) } catch (error) { res.send(baseStart + "