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

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

@ -91,8 +91,16 @@ uploadsController.uploadThumb = function(req, res, next) {
}, next); }, next);
}; };
uploadsController.uploadGroupCover = function(data, next) { uploadsController.uploadGroupCover = function(uid, uploadedFile, callback) {
uploadImage(0, data, next); 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) { 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'; var filename = uploadedFile.name || 'upload';
filename = Date.now() + '-' + validator.escape(filename).substr(0, 255); 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.setGroupField(groupName, 'cover:position', position, callback);
}; };
Groups.updateCover = function(data, callback) { Groups.updateCover = function(uid, data, callback) {
var tempPath, md5sum, url; var tempPath, md5sum, url;
// Position only? That's fine // Position only? That's fine
@ -153,7 +153,7 @@ module.exports = function(Groups) {
}, next); }, next);
}, },
function(next) { function(next) {
uploadsController.uploadGroupCover({ uploadsController.uploadGroupCover(uid, {
name: 'groupCover', name: 'groupCover',
path: data.file ? data.file : tempPath path: data.file ? data.file : tempPath
}, function(err, uploadData) { }, function(err, uploadData) {

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

Loading…
Cancel
Save