From 3e3d72d06049fe8c661850bce2ef536b27b663fc Mon Sep 17 00:00:00 2001 From: Mhykol Date: Wed, 5 Jun 2024 05:39:28 -0400 Subject: Modified for user generated scripts and css --- app.js | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'app.js') diff --git a/app.js b/app.js index b206cb1..433d0b1 100644 --- a/app.js +++ b/app.js @@ -25,7 +25,7 @@ const mime = { mp4: 'video/mp4', webm: 'video/webm' } -const assets = [ +const assetDir = [ 'js', 'css', 'img', @@ -59,7 +59,7 @@ class App { string: req.path } - if (assets.includes(this.path.split[1])) { + if (assetDir.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 { @@ -99,25 +99,30 @@ class App { if (output.has(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 object = { + js: output.assets.js, + css: output.assets.css + } + + this.readfile.Create(output.html).then(output => { + const DOMPurify = createDOMPurify(new JSDOM('').window) 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) + res.send(JSON.stringify({html: clean, css: object.css, js: object.js})) }) }) } 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 object = { + js: output.assets.js, + css: output.assets.css + } + this.readfile.Create(output.html).then(output => { + const DOMPurify = createDOMPurify(new JSDOM('').window) 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) + res.send(JSON.stringify({html: clean, css: object.css, js: object.js})) }) } } else { -- cgit v1.2.3-70-g09d2