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, pid: threadData.pid,
title: threadData.title || '', title: threadData.title || '',
body: threadData.body || '', body: threadData.body || '',
images: [] images: threadData.uploadedImages
}; };
composer.load(uuid); composer.load(uuid);
} else { } else {

@ -369,28 +369,31 @@ var RDB = require('./redis.js'),
var imgur = require('./imgur'); var imgur = require('./imgur');
imgur.setClientID(meta.config.imgurClientID); 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) { imgur.upload(image.data, 'base64', function(err, data) {
if(err) { if(err) {
callback(err); next(err);
} else { } else {
if(data.success) { if(data.success) {
var img= {url:data.data.link, name:image.name}; var img= {url:data.data.link, name:image.name};
uploadedImages.push(img); uploadedImages.push(img);
callback(null); next(null);
} else { } else {
winston.error('Can\'t upload image, did you set imgurClientID?'); 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) { async.each(images, uploadImage, function(err) {
if(!err) { if(!err) {
Posts.setPostField(pid, 'uploadedImages', JSON.stringify(uploadedImages)); Posts.setPostField(pid, 'uploadedImages', JSON.stringify(uploadedImages));
@ -401,7 +404,6 @@ var RDB = require('./redis.js'),
} }
}); });
} }
}
Posts.getPostsByUid = function(uid, start, end, callback) { 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 (uid > 0) {
if (parseInt(data.tid) > 0) { if (parseInt(data.tid) > 0) {
topics.getTopicData(data.tid, function(topicData) { topics.getTopicData(data.tid, function(topicData) {
if (data.body) if (data.body)
topicData.body = 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) { } else if (parseInt(data.pid) > 0) {
async.parallel([ async.parallel([
function(next) { 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); next(null, raw);
}); });
}, },
@ -621,7 +628,8 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
socket.emit('api:composer.push', { socket.emit('api:composer.push', {
title: results[1], title: results[1],
pid: data.pid, pid: data.pid,
body: results[0] body: results[0].content,
uploadedImages: results[0].uploadedImages
}); });
}); });
} }

Loading…
Cancel
Save