fixed posts not appearing immediately

v1.18.x
Baris Soner Usakli 11 years ago
parent 01102d5982
commit 81e5cf0cf3

@ -462,7 +462,7 @@ define(function() {
adjust_rep(-1, data.pid, data.uid); adjust_rep(-1, data.pid, data.uid);
}); });
socket.on('event:new_post', app.createNewPosts); socket.on('event:new_post', createNewPosts);
socket.on('event:topic_deleted', function(data) { socket.on('event:topic_deleted', function(data) {
if (data.tid === tid && data.status === 'ok') { if (data.tid === tid && data.status === 'ok') {

@ -1,12 +1,11 @@
var request = require('request'); var request = require('request'),
winston = require('winston');
(function (imgur) { (function (imgur) {
"use strict"; "use strict";
var clientID = ''; imgur.upload = function (clientID, image, type, callback) {
imgur.upload = function (image, type, callback) {
var options = { var options = {
url: 'https://api.imgur.com/3/upload.json', url: 'https://api.imgur.com/3/upload.json',
headers: { headers: {
@ -15,21 +14,27 @@ var request = require('request');
}; };
var post = request.post(options, function (err, req, body) { var post = request.post(options, function (err, req, body) {
if(err) {
return callback(err, null);
}
try { try {
callback(err, JSON.parse(body)); var response = JSON.parse(body);
} catch (e) { if(response.success) {
callback(err, body); callback(null, response.data);
} else {
callback(new Error(response.data.error.message), null);
}
} catch(e) {
winston.error('Unable to parse Imgur json response. [' + body +']');
callback(e, null);
} }
}); });
var upload = post.form({ post.form({
type: type, type: type,
image: image image: image
}); });
}; };
imgur.setClientID = function (id) {
clientID = id;
};
}(exports)); }(exports));

@ -450,24 +450,18 @@ var RDB = require('./redis.js'),
} }
Posts.uploadPostImage = function(image, callback) { Posts.uploadPostImage = function(image, callback) {
var imgur = require('./imgur');
imgur.setClientID(meta.config.imgurClientID);
if(!image) if(!image)
return callback('invalid image', null); return callback('invalid image', null);
imgur.upload(image.data, 'base64', function(err, data) { require('./imgur').upload(meta.config.imgurClientID, image.data, 'base64', function(err, data) {
if(err) { if(err) {
callback('Can\'t upload image!', null); callback(err.message, null);
} else { } else {
if(data.success) { callback(null, {
var img= {url:data.data.link, name:image.name}; url: data.link,
name: image.name
callback(null, img); });
} else {
winston.error('Can\'t upload image, did you set imgurClientID?');
callback("upload error", null);
}
} }
}); });
} }

Loading…
Cancel
Save