more picture tests

v1.18.x
Barış Soner Uşaklı 8 years ago
parent a513d98e1d
commit 5cb53406fe

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

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save