refactor: uploadController.js

some logic improvements
This commit is contained in:
Bobby Wibowo 2022-07-28 13:26:15 +07:00
parent 301cf3377d
commit 03eff45e8c
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF

View File

@ -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.') throw new ClientError('Empty files are not allowed.')
} }
} }
}).catch(error => { }).catch(error => {
// Unlink temp files (do not wait) // Unlink temp files (do not wait)
if (Array.isArray(req.files) && req.files.length) { if (req.files.length) {
unlinkFiles(req.files) unlinkFiles(req.files)
} }
@ -637,9 +638,8 @@ self.actuallyUploadUrls = async (req, res, user, data = {}) => {
// Unlink temp files (do not wait) // Unlink temp files (do not wait)
if (filesData.length) { if (filesData.length) {
Promise.all(filesData.map(async file => { Promise.all(filesData.map(async file => {
if (file.filename) { if (!file.filename) return
utils.unlinkFile(file.filename).catch(logger.error) return utils.unlinkFile(file.filename).catch(logger.error)
}
})) }))
} }