|
|
|
@ -1,12 +1,12 @@
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
var async = require('async');
|
|
|
|
|
var winston = require('winston');
|
|
|
|
|
var path = require('path');
|
|
|
|
|
var nconf = require('nconf');
|
|
|
|
|
|
|
|
|
|
var user = require('../../user');
|
|
|
|
|
var plugins = require('../../plugins');
|
|
|
|
|
var file = require('../../file');
|
|
|
|
|
|
|
|
|
|
module.exports = function (SocketUser) {
|
|
|
|
|
SocketUser.changePicture = function (socket, data, callback) {
|
|
|
|
@ -38,11 +38,7 @@ module.exports = function (SocketUser) {
|
|
|
|
|
type: type,
|
|
|
|
|
picture: undefined,
|
|
|
|
|
}, function (err, returnData) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
next(null, returnData.picture || '');
|
|
|
|
|
next(err, returnData && returnData.picture);
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
@ -71,7 +67,7 @@ module.exports = function (SocketUser) {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SocketUser.removeUploadedPicture = function (socket, data, callback) {
|
|
|
|
|
if (!socket.uid || !data.uid) {
|
|
|
|
|
if (!socket.uid || !data || !data.uid) {
|
|
|
|
|
return callback(new Error('[[error:invalid-data]]'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -86,11 +82,7 @@ module.exports = function (SocketUser) {
|
|
|
|
|
if (userData.uploadedpicture && !userData.uploadedpicture.startsWith('http')) {
|
|
|
|
|
var pathToFile = path.join(nconf.get('base_dir'), 'public', userData.uploadedpicture);
|
|
|
|
|
if (pathToFile.startsWith(nconf.get('upload_path'))) {
|
|
|
|
|
require('fs').unlink(pathToFile, function (err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
winston.error(err);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
file.delete(pathToFile);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -109,27 +101,27 @@ module.exports = function (SocketUser) {
|
|
|
|
|
if (!data || !data.uid) {
|
|
|
|
|
return callback(new Error('[[error:invalid-data]]'));
|
|
|
|
|
}
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
async.parallel({
|
|
|
|
|
list: async.apply(plugins.fireHook, 'filter:user.listPictures', {
|
|
|
|
|
uid: data.uid,
|
|
|
|
|
pictures: [],
|
|
|
|
|
}),
|
|
|
|
|
uploaded: async.apply(user.getUserField, data.uid, 'uploadedpicture'),
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
function (data, next) {
|
|
|
|
|
if (data.uploaded) {
|
|
|
|
|
data.list.pictures.push({
|
|
|
|
|
type: 'uploaded',
|
|
|
|
|
url: data.uploaded,
|
|
|
|
|
text: '[[user:uploaded_picture]]',
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async.parallel({
|
|
|
|
|
list: async.apply(plugins.fireHook, 'filter:user.listPictures', {
|
|
|
|
|
uid: data.uid,
|
|
|
|
|
pictures: [],
|
|
|
|
|
}),
|
|
|
|
|
uploaded: async.apply(user.getUserField, data.uid, 'uploadedpicture'),
|
|
|
|
|
}, function (err, data) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (data.uploaded) {
|
|
|
|
|
data.list.pictures.push({
|
|
|
|
|
type: 'uploaded',
|
|
|
|
|
url: data.uploaded,
|
|
|
|
|
text: '[[user:uploaded_picture]]',
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback(null, data.list.pictures);
|
|
|
|
|
});
|
|
|
|
|
next(null, data.list.pictures);
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|