|
|
|
@ -8,7 +8,6 @@ var nconf = require('nconf');
|
|
|
|
|
var crypto = require('crypto');
|
|
|
|
|
var winston = require('winston');
|
|
|
|
|
var request = require('request');
|
|
|
|
|
var mime = require('mime');
|
|
|
|
|
|
|
|
|
|
var plugins = require('../plugins');
|
|
|
|
|
var file = require('../file');
|
|
|
|
@ -43,7 +42,10 @@ module.exports = function (User) {
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
if (plugins.hasListeners('filter:uploadImage')) {
|
|
|
|
|
return plugins.fireHook('filter:uploadImage', {image: picture, uid: updateUid}, next);
|
|
|
|
|
return plugins.fireHook('filter:uploadImage', {
|
|
|
|
|
image: picture,
|
|
|
|
|
uid: updateUid
|
|
|
|
|
}, next);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var filename = updateUid + '-profileimg' + (keepAllVersions ? '-' + Date.now() : '') + (convertToPNG ? '.png' : extension);
|
|
|
|
@ -79,7 +81,10 @@ module.exports = function (User) {
|
|
|
|
|
},
|
|
|
|
|
function (_image, next) {
|
|
|
|
|
uploadedImage = _image;
|
|
|
|
|
User.setUserFields(updateUid, {uploadedpicture: uploadedImage.url, picture: uploadedImage.url}, next);
|
|
|
|
|
User.setUserFields(updateUid, {
|
|
|
|
|
uploadedpicture: uploadedImage.url,
|
|
|
|
|
picture: uploadedImage.url
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
function (next) {
|
|
|
|
|
next(null, uploadedImage);
|
|
|
|
@ -99,7 +104,7 @@ module.exports = function (User) {
|
|
|
|
|
var uploadSize = parseInt(meta.config.maximumProfileImageSize, 10) || 256;
|
|
|
|
|
var size = res.headers['content-length'];
|
|
|
|
|
var type = res.headers['content-type'];
|
|
|
|
|
var extension = mime.extension(type);
|
|
|
|
|
var extension = file.typeToExtension(type);
|
|
|
|
|
|
|
|
|
|
if (['png', 'jpeg', 'jpg', 'gif'].indexOf(extension) === -1) {
|
|
|
|
|
return callback(new Error('[[error:invalid-image-extension]]'));
|
|
|
|
@ -109,12 +114,21 @@ module.exports = function (User) {
|
|
|
|
|
return callback(new Error('[[error:file-too-big, ' + uploadSize + ']]'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var picture = {url: url, name: ''};
|
|
|
|
|
plugins.fireHook('filter:uploadImage', {image: picture, uid: uid}, function (err, image) {
|
|
|
|
|
var picture = {
|
|
|
|
|
url: url,
|
|
|
|
|
name: ''
|
|
|
|
|
};
|
|
|
|
|
plugins.fireHook('filter:uploadImage', {
|
|
|
|
|
image: picture,
|
|
|
|
|
uid: uid
|
|
|
|
|
}, function (err, image) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
User.setUserFields(uid, {uploadedpicture: image.url, picture: image.url});
|
|
|
|
|
User.setUserFields(uid, {
|
|
|
|
|
uploadedpicture: image.url,
|
|
|
|
|
picture: image.url
|
|
|
|
|
});
|
|
|
|
|
callback(null, image);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
@ -170,10 +184,14 @@ module.exports = function (User) {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (plugins.hasListeners('filter:uploadImage')) {
|
|
|
|
|
return plugins.fireHook('filter:uploadImage', {image: image, uid: data.uid}, next);
|
|
|
|
|
return plugins.fireHook('filter:uploadImage', {
|
|
|
|
|
image: image,
|
|
|
|
|
uid: data.uid
|
|
|
|
|
}, next);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var filename = data.uid + '-profilecover' + (keepAllVersions ? '-' + Date.now() : '');
|
|
|
|
|
var extension = file.typeToExtension(data.imageData.slice(5, data.imageData.indexOf('base64') - 1));
|
|
|
|
|
var filename = data.uid + '-profilecover' + (keepAllVersions ? '-' + Date.now() : '') + (extension || '');
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
file.isFileTypeAllowed(data.file.path, next);
|
|
|
|
@ -208,20 +226,25 @@ module.exports = function (User) {
|
|
|
|
|
winston.error(unlinkErr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback(err); // send back the original error
|
|
|
|
|
callback(err); // send back the original error
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (data.position) {
|
|
|
|
|
User.updateCoverPosition(data.uid, data.position, function (err) {
|
|
|
|
|
callback(err, {url: url});
|
|
|
|
|
callback(err, {
|
|
|
|
|
url: url
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
callback(err, {
|
|
|
|
|
url: url
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
callback(err, {url: url});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
User.uploadCroppedPicture = function (data, callback) {
|
|
|
|
|
var keepAllVersions = parseInt(meta.config['profile:keepAllUserImages'], 10) === 1;
|
|
|
|
|
var url, md5sum;
|
|
|
|
@ -229,7 +252,7 @@ module.exports = function (User) {
|
|
|
|
|
if (!data.imageData) {
|
|
|
|
|
return callback(new Error('[[error:invalid-data]]'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
var size = data.file ? data.file.size : data.imageData.length;
|
|
|
|
@ -260,10 +283,14 @@ module.exports = function (User) {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (plugins.hasListeners('filter:uploadImage')) {
|
|
|
|
|
return plugins.fireHook('filter:uploadImage', {image: image, uid: data.uid}, next);
|
|
|
|
|
return plugins.fireHook('filter:uploadImage', {
|
|
|
|
|
image: image,
|
|
|
|
|
uid: data.uid
|
|
|
|
|
}, next);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var filename = data.uid + '-profileavatar' + (keepAllVersions ? '-' + Date.now() : '');
|
|
|
|
|
var extension = file.typeToExtension(data.imageData.slice(5, data.imageData.indexOf('base64') - 1));
|
|
|
|
|
var filename = data.uid + '-profileavatar' + (keepAllVersions ? '-' + Date.now() : '') + (extension || '');
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
file.isFileTypeAllowed(data.file.path, next);
|
|
|
|
@ -281,7 +308,10 @@ module.exports = function (User) {
|
|
|
|
|
},
|
|
|
|
|
function (uploadData, next) {
|
|
|
|
|
url = uploadData.url;
|
|
|
|
|
User.setUserFields(data.uid, {uploadedpicture: url, picture: url}, next);
|
|
|
|
|
User.setUserFields(data.uid, {
|
|
|
|
|
uploadedpicture: url,
|
|
|
|
|
picture: url
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
function (next) {
|
|
|
|
|
fs.unlink(data.file.path, function (err) {
|
|
|
|
@ -293,10 +323,12 @@ module.exports = function (User) {
|
|
|
|
|
}
|
|
|
|
|
], function (err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
callback(err); // send back the original error
|
|
|
|
|
callback(err); // send back the original error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback(err, {url: url});
|
|
|
|
|
callback(err, {
|
|
|
|
|
url: url
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|