From 02f751ca9b494e066410ef5681d7a20902ba9cac Mon Sep 17 00:00:00 2001 From: tycrek Date: Tue, 6 Apr 2021 15:09:19 -0600 Subject: [PATCH] improved resource 404 handling --- ass.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ass.js b/ass.js index 04ed2c6..b41f6f2 100755 --- a/ass.js +++ b/ass.js @@ -79,10 +79,13 @@ function startup() { let resourceId = req.params.resourceId.split('.')[0]; let fileData = fs.readFileSync(path(data[resourceId].path)); - if (data[resourceId]) - res.header('Accept-Ranges', 'bytes').header('Content-Length', fileData.byteLength).type(data[resourceId].mimetype).send(fileData); - else - res.sendStatus(404); + if (!resourceId || !data[resourceId]) return res.sendStatus(404); + fs.readFile(path(data[resourceId].path)) + .then((fileData) => res + .header('Accept-Ranges', 'bytes') + .header('Content-Length', fileData.byteLength) + .type(data[resourceId].mimetype).send(fileData)) + .catch(console.error); }); // Delete file