From d77233fe518c2c6ca5653bbb18a7fb94bade0cb9 Mon Sep 17 00:00:00 2001 From: Mhykol Date: Sat, 1 Jun 2024 05:24:12 -0400 Subject: Update app.js --- app.js | 77 ++++++++++++++++++++++++++++++++---------------------------------- 1 file changed, 37 insertions(+), 40 deletions(-) (limited to 'app.js') diff --git a/app.js b/app.js index 31609a0..b206cb1 100644 --- a/app.js +++ b/app.js @@ -25,6 +25,12 @@ const mime = { mp4: 'video/mp4', webm: 'video/webm' } +const assets = [ + 'js', + 'css', + 'img', + 'vid' +] require('dotenv').config() // Handles the routes @@ -45,23 +51,6 @@ class App { })) } - app.get('/js/*', this.#Logger, (req, res) => { - const data = this.readfile.GetFile(req.path) - data.mime.then(output => this.#FileOpen({data: data, mime: output, res: res})) - }) - app.get('/css/*', this.#Logger, (req, res) => { - const data = this.readfile.GetFile(req.path) - data.mime.then(output => this.#FileOpen({data: data, mime: output, res: res})) - }) - app.get('/img/*', this.#Logger, (req, res) => { - const data = this.readfile.GetFile(req.path) - data.mime.then(output => this.#FileOpen({data: data, mime: output, res: res})) - }) - app.get('/vid/*', this.#Logger, (req, res) => { - const data = this.readfile.GetFile(req.path) - data.mime.then(output => this.#FileOpen({data: data, mime: output, res: res})) - }) - app.route('*') .get(this.#ValidateCookie, this.#Logger, (req, res) => { this.controller.Main().then(output => { @@ -70,27 +59,32 @@ class App { string: req.path } - switch (this.path.split[1]) { - case 'favicon.ico': - this.data = this.readfile.GetFavicon() - this.data.mime.then(output => this.#FileOpen({data: this.data, mime: output, res: res})) - break - case 'robots.txt': - this.data = this.readfile.GetRobots() - this.data.mime.then(output => this.#FileOpen({data: this.data, mime: output, res: res})) - break - default: - if (this.path.string.endsWith('/') && this.path.string.length > 1) this.path.string = this.path.string.substring(0, this.path.string.length - 1) - if (output.has(this.path.string)) { - try { - output.get(this.path.string).then(output => res.send(this.readfile.GetMain(output.meta))) - } catch { - res.send(this.readfile.GetMain(output.get(this.path.string))) + if (assets.includes(this.path.split[1])) { + const data = this.readfile.GetFile(req.path) + data.mime.then(output => this.#FileOpen({data: data, mime: output, res: res})) + } else { + switch (this.path.split[1]) { + case 'favicon.ico': + this.data = this.readfile.GetFavicon() + this.data.mime.then(output => this.#FileOpen({data: this.data, mime: output, res: res})) + break + case 'robots.txt': + this.data = this.readfile.GetRobots() + this.data.mime.then(output => this.#FileOpen({data: this.data, mime: output, res: res})) + break + default: + if (this.path.string.endsWith('/') && this.path.string.length > 1) this.path.string = this.path.string.substring(0, this.path.string.length - 1) + if (output.has(this.path.string)) { + try { + output.get(this.path.string).then(output => res.send(this.readfile.GetMain(output.meta))) + } catch { + res.send(this.readfile.GetMain(output.get(this.path.string))) + } + } else { + res.sendStatus(404) } - } else { - res.sendStatus(404) - } - break + break + } } }) }) @@ -103,14 +97,15 @@ class App { if (this.path.string.endsWith('/') && this.path.string.length > 1) this.path.string = this.path.string.substring(0, this.path.string.length - 1) this.controller.Main(req.body.value).then(output => { if (output.has(this.path.string)) { - const data = this.readfile.Create(output.get(this.path.string)) try { output.get(this.path.string).then(output => { const object = this.readfile.Create(output.html) const window = new JSDOM('').window const DOMPurify = createDOMPurify(window) object.then(output => { - const clean = DOMPurify.sanitize(output.layouts.header + output.layouts.data + output.layouts.footer, { ADD_TAGS: ["iframe"], ADD_ATTR: ['allow', 'allowfullscreen', 'frameborder', 'scrolling'] }) + const clean = DOMPurify.sanitize(output.layouts.header + output.layouts.data + output.layouts.footer, { + ADD_TAGS: ["iframe"], ADD_ATTR: ['allow', 'allowfullscreen', 'frameborder', 'scrolling'] + }) res.send(clean) }) }) @@ -119,7 +114,9 @@ class App { const window = new JSDOM('').window const DOMPurify = createDOMPurify(window) object.then(output => { - const clean = DOMPurify.sanitize(output.layouts.header + output.layouts.data + output.layouts.footer, { ADD_TAGS: ['iframe'], ADD_ATTR: ['allow', 'allowfullscreen', 'frameborder', 'scrolling'] }) + const clean = DOMPurify.sanitize(output.layouts.header + output.layouts.data + output.layouts.footer, { + ADD_TAGS: ['iframe'], ADD_ATTR: ['allow', 'allowfullscreen', 'frameborder', 'scrolling'] + }) res.send(clean) }) } -- cgit v1.2.3-70-g09d2