Adds the filter:uploadStored hook which fires after the file is saved… (#5798)

* 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.
v1.18.x
dbolack-ab 8 years ago committed by Barış Soner Uşaklı
parent b983be2919
commit c1452db0ba

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

Loading…
Cancel
Save