From 2b994a685bf849144049343cf24b653bb42369ed Mon Sep 17 00:00:00 2001 From: Mhykol Date: Tue, 28 May 2024 10:41:49 -0400 Subject: Added meta tags to scripts and improved controller --- app.js | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'app.js') diff --git a/app.js b/app.js index 3998b0b..31609a0 100644 --- a/app.js +++ b/app.js @@ -81,9 +81,16 @@ class App { 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)) {res.send(this.readfile.GetMain())} else {res.sendStatus(404)} + 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) + } break - } }) }) @@ -97,17 +104,25 @@ class App { this.controller.Main(req.body.value).then(output => { if (output.has(this.path.string)) { const data = this.readfile.Create(output.get(this.path.string)) - data.then(output => { - try { + try { + output.get(this.path.string).then(output => { + const object = this.readfile.Create(output.html) const window = new JSDOM('').window const DOMPurify = createDOMPurify(window) - const clean = DOMPurify.sanitize(output.layouts.header + output.layouts.data + output.layouts.footer, { ADD_TAGS: ["iframe"], ADD_ATTR: ['allow', 'allowfullscreen', 'frameborder', 'scrolling'] }) + 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'] }) + res.send(clean) + }) + }) + } catch { + const object = this.readfile.Create(output.get(this.path.string).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'] }) res.send(clean) - } catch (err) { - logger.Error(err) - res.send('Not Found') - } - }) + }) + } } else { res.send('Not Found') } -- cgit v1.2.3-70-g09d2