From 03eff45e8c7fb5ac7b65e2b835f9543d7ff6dbd3 Mon Sep 17 00:00:00 2001 From: Bobby Wibowo Date: Thu, 28 Jul 2022 13:26:15 +0700 Subject: [PATCH] refactor: uploadController.js some logic improvements --- controllers/uploadController.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/controllers/uploadController.js b/controllers/uploadController.js index 41a0483..aeddf1a 100644 --- a/controllers/uploadController.js +++ b/controllers/uploadController.js @@ -440,13 +440,14 @@ self.actuallyUpload = async (req, res, user, data = {}) => { } }) - if (config.filterEmptyFile && file.size === 0) { + // file.size is not populated if a chunk upload, so ignore + if (config.filterEmptyFile && !file.isChunk && file.size === 0) { throw new ClientError('Empty files are not allowed.') } } }).catch(error => { // Unlink temp files (do not wait) - if (Array.isArray(req.files) && req.files.length) { + if (req.files.length) { unlinkFiles(req.files) } @@ -637,9 +638,8 @@ self.actuallyUploadUrls = async (req, res, user, data = {}) => { // Unlink temp files (do not wait) if (filesData.length) { Promise.all(filesData.map(async file => { - if (file.filename) { - utils.unlinkFile(file.filename).catch(logger.error) - } + if (!file.filename) return + return utils.unlinkFile(file.filename).catch(logger.error) })) }