|
|
@ -10,7 +10,6 @@ var mime = require('mime');
|
|
|
|
var winston = require('winston');
|
|
|
|
var winston = require('winston');
|
|
|
|
|
|
|
|
|
|
|
|
var db = require('../database');
|
|
|
|
var db = require('../database');
|
|
|
|
var file = require('../file');
|
|
|
|
|
|
|
|
var uploadsController = require('../controllers/uploads');
|
|
|
|
var uploadsController = require('../controllers/uploads');
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = function (Groups) {
|
|
|
|
module.exports = function (Groups) {
|
|
|
@ -25,7 +24,7 @@ module.exports = function (Groups) {
|
|
|
|
Groups.updateCover = function (uid, data, callback) {
|
|
|
|
Groups.updateCover = function (uid, data, callback) {
|
|
|
|
|
|
|
|
|
|
|
|
// Position only? That's fine
|
|
|
|
// Position only? That's fine
|
|
|
|
if (!data.imageData && data.position) {
|
|
|
|
if (!data.imageData && !data.file && data.position) {
|
|
|
|
return Groups.updateCoverPosition(data.groupName, data.position, callback);
|
|
|
|
return Groups.updateCoverPosition(data.groupName, data.position, callback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -66,26 +65,19 @@ module.exports = function (Groups) {
|
|
|
|
Groups.setGroupField(data.groupName, 'cover:thumb:url', uploadData.url, next);
|
|
|
|
Groups.setGroupField(data.groupName, 'cover:thumb:url', uploadData.url, next);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
function (next) {
|
|
|
|
function (next) {
|
|
|
|
fs.unlink(tempPath, next); // Delete temporary file
|
|
|
|
if (data.position) {
|
|
|
|
|
|
|
|
Groups.updateCoverPosition(data.groupName, data.position, next);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
next(null);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
], function (err) {
|
|
|
|
], function (err) {
|
|
|
|
if (err) {
|
|
|
|
fs.unlink(tempPath, function (unlinkErr) {
|
|
|
|
return fs.unlink(tempPath, function (unlinkErr) {
|
|
|
|
|
|
|
|
if (unlinkErr) {
|
|
|
|
if (unlinkErr) {
|
|
|
|
winston.error(unlinkErr);
|
|
|
|
winston.error(unlinkErr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
callback(err); // send back original error
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (data.position) {
|
|
|
|
|
|
|
|
Groups.updateCoverPosition(data.groupName, data.position, function (err) {
|
|
|
|
|
|
|
|
callback(err, {url: url});
|
|
|
|
callback(err, {url: url});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
|
|
|
|
callback(err, {url: url});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|