From c1452db0ba98e4a98555cdb61722a9f178fcaad0 Mon Sep 17 00:00:00 2001 From: dbolack-ab Date: Mon, 17 Jul 2017 17:15:24 -0500 Subject: [PATCH] =?UTF-8?q?Adds=20the=20filter:uploadStored=20hook=20which?= =?UTF-8?q?=20fires=20after=20the=20file=20is=20saved=E2=80=A6=20(#5798)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Adds the filter:uploadStored hook which fires after the file is saved in the async waterfall and passes: var storedFile = { url: nconf.get('relative_path') + upload.url, path: upload.path, name: uploadedFile.name, } plugins.fireHook( 'filter:uploadStored', { uploadedFile: uploadedFile, storedFile: storedFile } ); * Corrections per PR. Should match style guide. * Correction attempts take 2. Per: /home/travis/build/NodeBB/NodeBB/src/controllers/uploads.js 234:5 error Missing semicolon semi 235:3 error Expected indentation of 3 tabs but found 2 indent 235:19 error There should be no spaces inside this paren space-in-parens 235:105 error There should be no spaces inside this paren space-in-parens 236:3 error Expected indentation of 3 tabs but found 2 indent * next() shouldn't fire twice, but I see no documentation suggesting that the paramaters will fire correctly. Previous comments imply it is preferred to have fireHook fire fof the callback rather than having it happen next, so I'm wrapping next in an anonymous function to ensure it passes the parameters. If this is not the preferred method, please provide a thorough correction. * Meh. Figuring out this style requirement is so hit and miss. * Corrected for proper callback? technique. Might blow up on style. Will watch. --- src/controllers/uploads.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/controllers/uploads.js b/src/controllers/uploads.js index ab651d1325..733ddc95ec 100644 --- a/src/controllers/uploads.js +++ b/src/controllers/uploads.js @@ -227,10 +227,17 @@ function saveFileToLocal(uploadedFile, callback) { file.saveFileToLocal(filename, 'files', uploadedFile.path, next); }, function (upload, next) { - next(null, { + var storedFile = { url: nconf.get('relative_path') + upload.url, path: upload.path, name: uploadedFile.name, + }; + + plugins.fireHook('filter:uploadStored', { uploadedFile: uploadedFile, storedFile: storedFile }, function (err, data) { + if (err) { + return next(err); + } + next(null, data.storedFile); }); }, ], callback);