From f9a8edb1a0a483ed675c688c7ddb2ad662c36e5c Mon Sep 17 00:00:00 2001 From: Naz Date: Mon, 25 Oct 2021 15:06:25 +0400 Subject: [PATCH] Refactored upload middleware refs https://linear.app/tryghost/issue/CORE-121/create-a-video-storage-adapter - Using a wrapping object to store enableClear/multer instances didn't make any sense --- core/server/web/api/middleware/upload.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/core/server/web/api/middleware/upload.js b/core/server/web/api/middleware/upload.js index 929f69048d..806c103b56 100644 --- a/core/server/web/api/middleware/upload.js +++ b/core/server/web/api/middleware/upload.js @@ -34,20 +34,19 @@ const messages = { } }; -const upload = { - enabledClear: config.get('uploadClear') || true, - multer: multer({dest: os.tmpdir()}) -}; +const enabledClear = config.get('uploadClear') || true; +const upload = multer({dest: os.tmpdir()}); const deleteSingleFile = file => fs.unlink(file.path).catch(err => logging.error(err)); const single = name => (req, res, next) => { - const singleUpload = upload.multer.single(name); + const singleUpload = upload.single(name); + singleUpload(req, res, (err) => { if (err) { return next(err); } - if (upload.enabledClear) { + if (enabledClear) { const deleteFiles = () => { res.removeListener('finish', deleteFiles); res.removeListener('close', deleteFiles);