|
|
|
@ -165,8 +165,7 @@ var fs = require('fs'),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var convertToPNG = parseInt(meta.config['profile:convertProfileImageToPNG'], 10);
|
|
|
|
|
var filename = req.user.uid + '-profileimg' + (convertToPNG ? '.png' : extension);
|
|
|
|
|
var updateUid = req.params.uid;
|
|
|
|
|
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function(next) {
|
|
|
|
@ -174,16 +173,41 @@ var fs = require('fs'),
|
|
|
|
|
},
|
|
|
|
|
function(next) {
|
|
|
|
|
image.convertImageToPng(req.files.userPhoto.path, extension, next);
|
|
|
|
|
},
|
|
|
|
|
function(next) {
|
|
|
|
|
try {
|
|
|
|
|
var params = JSON.parse(req.body.params);
|
|
|
|
|
if(parseInt(updateUid, 10) === parseInt(params.uid, 10)) {
|
|
|
|
|
return next();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
user.isAdministrator(req.user.uid, function(err, isAdmin) {
|
|
|
|
|
if(err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!isAdmin) {
|
|
|
|
|
return res.json(403, {
|
|
|
|
|
error: 'Not allowed!'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
updateUid = params.uid;
|
|
|
|
|
next();
|
|
|
|
|
});
|
|
|
|
|
} catch(err) {
|
|
|
|
|
next(err);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
], function(err, result) {
|
|
|
|
|
|
|
|
|
|
function done(err, image) {
|
|
|
|
|
fs.unlink(req.files.userPhoto.path);
|
|
|
|
|
if(err) {
|
|
|
|
|
return res.send({error: err.message});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
user.setUserField(req.user.uid, 'uploadedpicture', image.url);
|
|
|
|
|
user.setUserField(req.user.uid, 'picture', image.url);
|
|
|
|
|
user.setUserField(updateUid, 'uploadedpicture', image.url);
|
|
|
|
|
user.setUserField(updateUid, 'picture', image.url);
|
|
|
|
|
res.json({
|
|
|
|
|
path: image.url
|
|
|
|
|
});
|
|
|
|
@ -194,26 +218,28 @@ var fs = require('fs'),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(plugins.hasListeners('filter:uploadImage')) {
|
|
|
|
|
plugins.fireHook('filter:uploadImage', req.files.userPhoto, done);
|
|
|
|
|
} else {
|
|
|
|
|
return plugins.fireHook('filter:uploadImage', req.files.userPhoto, done);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
user.getUserField(req.user.uid, 'uploadedpicture', function (err, oldpicture) {
|
|
|
|
|
if (!oldpicture) {
|
|
|
|
|
file.saveFileToLocal(filename, req.files.userPhoto.path, done);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var convertToPNG = parseInt(meta.config['profile:convertProfileImageToPNG'], 10);
|
|
|
|
|
var filename = updateUid + '-profileimg' + (convertToPNG ? '.png' : extension);
|
|
|
|
|
|
|
|
|
|
var absolutePath = path.join(nconf.get('base_dir'), nconf.get('upload_path'), path.basename(oldpicture));
|
|
|
|
|
user.getUserField(updateUid, 'uploadedpicture', function (err, oldpicture) {
|
|
|
|
|
if (!oldpicture) {
|
|
|
|
|
file.saveFileToLocal(filename, req.files.userPhoto.path, done);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fs.unlink(absolutePath, function (err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
winston.err(err);
|
|
|
|
|
}
|
|
|
|
|
var absolutePath = path.join(nconf.get('base_dir'), nconf.get('upload_path'), path.basename(oldpicture));
|
|
|
|
|
|
|
|
|
|
file.saveFileToLocal(filename, req.files.userPhoto.path, done);
|
|
|
|
|
});
|
|
|
|
|
fs.unlink(absolutePath, function (err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
winston.err(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
file.saveFileToLocal(filename, req.files.userPhoto.path, done);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|