From 68ab1e0183d8db8e0d4e4de468cb2813f10d67e5 Mon Sep 17 00:00:00 2001 From: Osman Mazinov Date: Fri, 20 Dec 2024 14:47:09 +0300 Subject: [PATCH] fix(uploadhandler): uncaught: TypeError [ERR_INVALID_ARG_TYPE]: The 'cb' argument must be of type function. Received undefined. fix(filehandler): express deprecated res.send(status). --- lib/filehandler.js | 2 +- lib/uploadhandler.js | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/filehandler.js b/lib/filehandler.js index e7e227a..7d99d9d 100644 --- a/lib/filehandler.js +++ b/lib/filehandler.js @@ -51,7 +51,7 @@ module.exports = function (middleware, options) { handler.destroy(); break; default: - res.send(405); + res.status(405).end(); } } }; diff --git a/lib/uploadhandler.js b/lib/uploadhandler.js index 070f018..8355f25 100644 --- a/lib/uploadhandler.js +++ b/lib/uploadhandler.js @@ -112,7 +112,11 @@ module.exports = function (options) { if (exists) { fileInfo.size = file.size; if (!fileInfo.validate()) { - fs.unlink(file.path); + try { + fs.unlinkSync(file.path); + } catch (e) { + console.error(e); + } finish(); return; } @@ -146,7 +150,11 @@ module.exports = function (options) { var os = fs.createWriteStream(options.uploadDir() + '/' + fileInfo.name); is.on('end', function (err) { if (!err) { - fs.unlink(file.path); + try { + fs.unlinkSync(file.path); + } catch (e) { + console.error(e); + } generatePreviews(); } finish(); @@ -163,7 +171,11 @@ module.exports = function (options) { _.each(tmpFiles, function (file) { var fileInfo = map[path.basename(file)]; self.emit('abort', fileInfo); - fs.unlink(file); + try { + fs.unlinkSync(file); + } catch (e) { + console.error(e); + } }); }) .on('error', function (e) { @@ -189,7 +201,11 @@ module.exports = function (options) { } fs.unlink(filepath, function (ex) { _.each(options.imageVersions, function (value, version) { - fs.unlink(path.join(options.uploadDir(), version, fileName)); + try { + fs.unlinkSync(path.join(options.uploadDir(), version, fileName)); + } catch (e) { + console.error(e); + } }); self.emit('delete', fileName); self.callback({success: !ex});