can add and remove images from posts

v1.18.x
Baris Usakli 12 years ago
parent 106157a951
commit d2eb73df96

@ -152,7 +152,7 @@ define(['taskbar'], function(taskbar) {
pid: threadData.pid,
title: threadData.title || '',
body: threadData.body || '',
images: []
images: threadData.uploadedImages
};
composer.load(uuid);
} else {

@ -369,28 +369,31 @@ var RDB = require('./redis.js'),
var imgur = require('./imgur');
imgur.setClientID(meta.config.imgurClientID);
var uploadedImages = [];
if(!images)
return callback(null, []);
var uploadedImages = images.filter(function(image) { return !!image.url; });
function uploadImage(image, next) {
if(!image.data)
return next(null);
function uploadImage(image, callback) {
imgur.upload(image.data, 'base64', function(err, data) {
if(err) {
callback(err);
next(err);
} else {
if(data.success) {
var img= {url:data.data.link, name:image.name};
uploadedImages.push(img);
callback(null);
next(null);
} else {
winston.error('Can\'t upload image, did you set imgurClientID?');
callback(data);
next(data);
}
}
});
}
if(!images) {
callback(null, uploadedImages);
} else {
async.each(images, uploadImage, function(err) {
if(!err) {
Posts.setPostField(pid, 'uploadedImages', JSON.stringify(uploadedImages));
@ -401,7 +404,6 @@ var RDB = require('./redis.js'),
}
});
}
}
Posts.getPostsByUid = function(uid, start, end, callback) {

@ -583,7 +583,6 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
if (uid > 0) {
if (parseInt(data.tid) > 0) {
topics.getTopicData(data.tid, function(topicData) {
if (data.body)
topicData.body = data.body;
@ -606,9 +605,17 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
}
});
} else if (parseInt(data.pid) > 0) {
async.parallel([
function(next) {
posts.getPostField(data.pid, 'content', function(raw) {
posts.getPostFields(data.pid, ['content', 'uploadedImages'], function(raw) {
try {
raw.uploadedImages = JSON.parse(raw.uploadedImages);
} catch(e) {
winston.err(e);
raw.uploadedImages = [];
}
next(null, raw);
});
},
@ -621,7 +628,8 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
socket.emit('api:composer.push', {
title: results[1],
pid: data.pid,
body: results[0]
body: results[0].content,
uploadedImages: results[0].uploadedImages
});
});
}

Loading…
Cancel
Save