diff --git a/src/controllers/accounts.js b/src/controllers/accounts.js index 515dc106c4..781e3fdb02 100644 --- a/src/controllers/accounts.js +++ b/src/controllers/accounts.js @@ -428,7 +428,7 @@ accountsController.uploadPicture = function (req, res, next) { }); } - var updateUid = req.user.uid; + var updateUid = req.user ? req.user.uid : 0; var imageDimension = parseInt(meta.config.profileImageDimension, 10) || 128; async.waterfall([ @@ -482,8 +482,8 @@ accountsController.uploadPicture = function (req, res, next) { return res.json({error:err.message}); } - if(plugins.hasListeners('filter:uploadImage')) { - return plugins.fireHook('filter:uploadImage', req.files.userPhoto, done); + if (plugins.hasListeners('filter:uploadImage')) { + return plugins.fireHook('filter:uploadImage', {image: req.files.userPhoto, uid: updateUid}, done); } var convertToPNG = parseInt(meta.config['profile:convertProfileImageToPNG'], 10) === 1; diff --git a/src/controllers/admin/uploads.js b/src/controllers/admin/uploads.js index 98a2386a9f..7306c54d28 100644 --- a/src/controllers/admin/uploads.js +++ b/src/controllers/admin/uploads.js @@ -2,8 +2,8 @@ var fs = require('fs'), path = require('path'), - file = require('./../../file'), - plugins = require('./../../plugins'); + file = require('../../file'), + plugins = require('../../plugins'); var uploadsController = {}; @@ -37,7 +37,7 @@ uploadsController.uploadImage = function(filename, folder, req, res) { } if (plugins.hasListeners('filter:uploadImage')) { - plugins.fireHook('filter:uploadImage', req.files.userPhoto, done); + plugins.fireHook('filter:uploadImage', {image: req.files.userPhoto, uid: req.user.uid}, done); } else { file.saveFileToLocal(filename, folder, req.files.userPhoto.path, done); } diff --git a/src/routes/api.js b/src/routes/api.js index aaf7a1b572..57f8122b06 100644 --- a/src/routes/api.js +++ b/src/routes/api.js @@ -55,7 +55,7 @@ function upload(req, res, filesIterator, next) { function uploadPost(req, res, next) { upload(req, res, function(file, next) { if(file.type.match(/image./)) { - uploadImage(file, next); + uploadImage(req.user.uid, file, next); } else { uploadFile(file, next); } @@ -75,7 +75,7 @@ function uploadThumb(req, res, next) { if (err) { return next(err); } - uploadImage(file, next); + uploadImage(req.user.uid, file, next); }); } else { next(new Error('[[error:invalid-file]]')); @@ -84,22 +84,22 @@ function uploadThumb(req, res, next) { } -function uploadImage(image, callback) { - if(plugins.hasListeners('filter:uploadImage')) { - plugins.fireHook('filter:uploadImage', image, callback); +function uploadImage(uid, image, callback) { + if (plugins.hasListeners('filter:uploadImage')) { + plugins.fireHook('filter:uploadImage', {image: image, uid: uid}, callback); } else { if (parseInt(meta.config.allowFileUploads, 10)) { - uploadFile(image, callback); + uploadFile(uid, image, callback); } else { callback(new Error('[[error:uploads-are-disabled]]')); } } } -function uploadFile(file, callback) { - if(plugins.hasListeners('filter:uploadFile')) { - plugins.fireHook('filter:uploadFile', file, callback); +function uploadFile(uid, file, callback) { + if (plugins.hasListeners('filter:uploadFile')) { + plugins.fireHook('filter:uploadFile', {file: file, uid: uid}, callback); } else { if(parseInt(meta.config.allowFileUploads, 10) !== 1) { diff --git a/src/socket.io/user.js b/src/socket.io/user.js index c68bab4841..c02d8ec8da 100644 --- a/src/socket.io/user.js +++ b/src/socket.io/user.js @@ -199,7 +199,7 @@ SocketUser.uploadProfileImageFromUrl = function(socket, url, callback) { return; } - plugins.fireHook('filter:uploadImage', {url: url}, function(err, image) { + plugins.fireHook('filter:uploadImage', {image: {url: url}, uid: socket.uid}, function(err, image) { if (err) { return callback(err); }