mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-07-07 02:33:47 +02:00
allow regular uploading (modal) of cover photo
This commit is contained in:
@@ -2,8 +2,9 @@
|
||||
/* globals define, app*/
|
||||
|
||||
define('coverPhoto', [
|
||||
'uploader',
|
||||
'vendor/jquery/draggable-background/backgroundDraggable'
|
||||
], function() {
|
||||
], function(uploader) {
|
||||
|
||||
var coverPhoto = {
|
||||
coverEl: null,
|
||||
@@ -17,6 +18,12 @@ define('coverPhoto', [
|
||||
coverPhoto.saveFn = saveFn;
|
||||
|
||||
coverEl.find('.change').on('click', function() {
|
||||
uploader.open(RELATIVE_PATH + '/api/groups/uploadpicture', { groupName: 'administrators' }, 0, function(imageUrlOnServer) {
|
||||
console.log(imageUrlOnServer);
|
||||
coverPhoto.coverEl.css('background-image', 'url(' + imageUrlOnServer + '?' + new Date().getTime() + ')');
|
||||
});
|
||||
|
||||
return;
|
||||
coverEl.toggleClass('active', 1);
|
||||
coverEl.backgroundDraggable({
|
||||
axis: 'y',
|
||||
|
||||
@@ -132,4 +132,19 @@ groupsController.members = function(req, res, next) {
|
||||
});
|
||||
};
|
||||
|
||||
groupsController.uploadCover = function(req, res, next) {
|
||||
var params = JSON.parse(req.body.params);
|
||||
|
||||
groups.updateCover({
|
||||
file: req.files.files[0].path,
|
||||
groupName: params.groupName
|
||||
}, function(err, image) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.json([{url: image.url.startsWith('http') ? image.url : nconf.get('relative_path') + image.url}]);
|
||||
})
|
||||
};
|
||||
|
||||
module.exports = groupsController;
|
||||
|
||||
@@ -123,6 +123,10 @@ module.exports = function(Groups) {
|
||||
|
||||
async.series([
|
||||
function(next) {
|
||||
if (data.file) {
|
||||
return next();
|
||||
}
|
||||
|
||||
// Calculate md5sum of image
|
||||
// This is required because user data can be private
|
||||
md5sum = crypto.createHash('md5');
|
||||
@@ -131,6 +135,10 @@ module.exports = function(Groups) {
|
||||
next();
|
||||
},
|
||||
function(next) {
|
||||
if (data.file) {
|
||||
return next();
|
||||
}
|
||||
|
||||
// Save image
|
||||
tempPath = path.join(nconf.get('base_dir'), nconf.get('upload_path'), md5sum);
|
||||
var buffer = new Buffer(data.imageData.slice(data.imageData.indexOf('base64') + 7), 'base64');
|
||||
@@ -142,7 +150,7 @@ module.exports = function(Groups) {
|
||||
function(next) {
|
||||
uploadsController.uploadGroupCover({
|
||||
name: 'groupCover',
|
||||
path: tempPath
|
||||
path: data.file ? data.file : tempPath
|
||||
}, function(err, uploadData) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
@@ -156,14 +164,20 @@ module.exports = function(Groups) {
|
||||
Groups.setGroupField(data.groupName, 'cover:url', url, next);
|
||||
},
|
||||
function(next) {
|
||||
fs.unlink(tempPath, next); // Delete temporary file
|
||||
fs.unlink(data.file ? data.file : tempPath, next); // Delete temporary file
|
||||
}
|
||||
], function(err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
Groups.updateCoverPosition(data.groupName, data.position, callback);
|
||||
if (data.position) {
|
||||
Groups.updateCoverPosition(data.groupName, data.position, function(err) {
|
||||
callback(err, {url: url});
|
||||
});
|
||||
} else {
|
||||
callback(err, {url: url});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -28,5 +28,7 @@ module.exports = function(app, middleware, controllers) {
|
||||
router.post('/post/upload', middlewares, uploadsController.uploadPost);
|
||||
router.post('/topic/thumb/upload', middlewares, uploadsController.uploadThumb);
|
||||
router.post('/user/:userslug/uploadpicture', middlewares.concat([middleware.authenticate, middleware.checkGlobalPrivacySettings, middleware.checkAccountPermissions]), controllers.accounts.edit.uploadPicture);
|
||||
|
||||
router.post('/groups/uploadpicture', middlewares.concat([middleware.authenticate]), controllers.groups.uploadCover);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user