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
This commit is contained in:
Naz 2021-10-25 15:06:25 +04:00 committed by naz
parent 4a551661d9
commit f9a8edb1a0

View File

@ -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);