Fixed cover loading for subdirs and added removal

re: #3832
v1.18.x
Julian Lam 9 years ago
parent 8ccfd235ad
commit f1412b6e9b

@ -23,6 +23,7 @@ define('coverPhoto', [
units: 'percent'
});
});
coverEl.find('.remove').on('click', coverPhoto.remove);
coverEl
.on('dragover', coverPhoto.onDragOver)
@ -79,5 +80,17 @@ define('coverPhoto', [
});
};
coverPhoto.remove = function() {
socket.emit('user.removeCover', {
uid: ajaxify.data.uid
}, function(err) {
if (!err) {
ajaxify.refresh();
} else {
app.alertError(err.message);
}
});
};
return coverPhoto;
});

@ -131,7 +131,7 @@ editController.uploadCoverPicture = function(req, res, next) {
return next(err);
}
res.json([{url: image.url.startsWith('http') ? image.url : nconf.get('relative_path') + image.url}]);
res.json([{ url: image.url }]);
});
};

@ -37,6 +37,20 @@ module.exports = function(SocketUser) {
});
};
SocketUser.removeCover = function(socket, data, callback) {
if (!socket.uid) {
return callback(new Error('[[error:no-privileges]]'));
}
user.isAdministrator(socket.uid, function(err, isAdmin) {
if (!isAdmin && data.uid !== socket.uid) {
return callback(new Error('[[error:no-privileges]]'));
}
user.removeCoverPicture(data, callback);
});
};
function isAdminOrSelfAndPasswordMatch(uid, data, callback) {
async.parallel({
isAdmin: async.apply(user.isAdministrator, uid),

@ -13,7 +13,8 @@ var async = require('async'),
plugins = require('../plugins'),
file = require('../file'),
image = require('../image'),
meta = require('../meta');
meta = require('../meta'),
db = require('../database');
module.exports = function(User) {
@ -198,4 +199,7 @@ module.exports = function(User) {
});
};
User.removeCoverPicture = function(data, callback) {
db.deleteObjectField('user:' + data.uid, 'cover:url', callback);
};
};
Loading…
Cancel
Save