From a49842a932b109386cad972f471775c04d1b0f03 Mon Sep 17 00:00:00 2001 From: Bobby Date: Tue, 4 Oct 2022 05:42:00 +0700 Subject: [PATCH] fix: size attribute of uploads with stripped tags it'd previously always keep size attribute before the tags stripping --- controllers/uploadController.js | 12 +++++++++--- controllers/utilsController.js | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/controllers/uploadController.js b/controllers/uploadController.js index 7bba48d..9f1fbce 100644 --- a/controllers/uploadController.js +++ b/controllers/uploadController.js @@ -527,6 +527,7 @@ self.actuallyUpload = async (req, res, data = {}) => { } } + // Strip tags, then update their size attribute, if required await self.stripTags(req, filesData) const stored = await self.storeFilesToDb(req, res, filesData) @@ -862,6 +863,7 @@ self.actuallyFinishChunks = async (req, res, files) => { } } + // Strip tags, then update their size attribute, if required await self.stripTags(req, filesData) const stored = await self.storeFilesToDb(req, res, filesData) @@ -971,9 +973,13 @@ self.stripTags = async (req, filesData) => { if (!self.parseStripTags(req.headers.striptags)) return try { - await Promise.all(filesData.map(async file => - utils.stripTags(file.filename, file.extname) - )) + await Promise.all(filesData.map(async file => { + // Update size attribute if applicable + const stat = await utils.stripTags(file.filename, file.extname) + if (stat) { + file.size = stat.size + } + })) } catch (error) { // Unlink temp files (do not wait) Promise.all(filesData.map(async file => diff --git a/controllers/utilsController.js b/controllers/utilsController.js index 8e1a5f1..d2ad0dd 100644 --- a/controllers/utilsController.js +++ b/controllers/utilsController.js @@ -613,7 +613,7 @@ self.stripTags = async (name, extname) => { throw new ServerError('An error occurred while stripping tags. The format may not be supported.') } - return true + return jetpack.inspectAsync(fullPath) } self.unlinkFile = async (filename, predb) => {