v1.18.x
barisusakli 9 years ago
parent d23e6758ba
commit 3ea453e8a0

@ -134,7 +134,7 @@ groupsController.members = function(req, res, next) {
groupsController.uploadCover = function(req, res, next) {
var params = JSON.parse(req.body.params);
groups.updateCover({
groups.updateCover(req.uid, {
file: req.files.files[0].path,
groupName: params.groupName
}, function(err, image) {

@ -91,8 +91,16 @@ uploadsController.uploadThumb = function(req, res, next) {
}, next);
};
uploadsController.uploadGroupCover = function(data, next) {
uploadImage(0, data, next);
uploadsController.uploadGroupCover = function(uid, uploadedFile, callback) {
if (plugins.hasListeners('filter:uploadImage')) {
return plugins.fireHook('filter:uploadImage', {image: uploadedFile, uid: uid}, callback);
}
if (plugins.hasListeners('filter:uploadFile')) {
return plugins.fireHook('filter:uploadFile', {file: uploadedFile, uid: uid}, callback);
}
saveFileToLocal(uploadedFile, callback);
};
function uploadImage(uid, image, callback) {
@ -132,6 +140,10 @@ function uploadFile(uid, uploadedFile, callback) {
}
}
saveFileToLocal(uploadedFile, callback);
}
function saveFileToLocal(uploadedFile, callback) {
var filename = uploadedFile.name || 'upload';
filename = Date.now() + '-' + validator.escape(filename).substr(0, 255);

@ -118,7 +118,7 @@ module.exports = function(Groups) {
Groups.setGroupField(groupName, 'cover:position', position, callback);
};
Groups.updateCover = function(data, callback) {
Groups.updateCover = function(uid, data, callback) {
var tempPath, md5sum, url;
// Position only? That's fine
@ -153,7 +153,7 @@ module.exports = function(Groups) {
}, next);
},
function(next) {
uploadsController.uploadGroupCover({
uploadsController.uploadGroupCover(uid, {
name: 'groupCover',
path: data.file ? data.file : tempPath
}, function(err, uploadData) {

@ -245,11 +245,11 @@ SocketGroups.cover.update = function(socket, data, callback) {
}
groups.ownership.isOwner(socket.uid, data.groupName, function(err, isOwner) {
if (!isOwner) {
return callback(new Error('[[error:no-privileges]]'));
if (err || !isOwner) {
return callback(err || new Error('[[error:no-privileges]]'));
}
groups.updateCover(data, callback);
groups.updateCover(socket.uid, data, callback);
});
};
@ -259,8 +259,8 @@ SocketGroups.cover.remove = function(socket, data, callback) {
}
groups.ownership.isOwner(socket.uid, data.groupName, function(err, isOwner) {
if (!isOwner) {
return callback(new Error('[[error:no-privileges]]'));
if (err || !isOwner) {
return callback(err || new Error('[[error:no-privileges]]'));
}
groups.removeCover(data, callback);

Loading…
Cancel
Save