From fd88aff195479c7af7ab5825d9480d6e5492e2ee Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Wed, 1 Jan 2014 14:11:12 -0500 Subject: [PATCH 1/4] mongo string fix --- src/database/mongo.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/database/mongo.js b/src/database/mongo.js index 9f1f8ea6a9..fceb39d00f 100644 --- a/src/database/mongo.js +++ b/src/database/mongo.js @@ -269,6 +269,9 @@ module.setObjectField = function(key, field, value, callback) { var data = {}; // if there is a '.' in the field name it inserts subdocument in mongo, replace '.'s with \uff0E + if(typeof field !== 'string') { + field = field.toString(); + } field = field.replace(/\./g, '\uff0E'); data[field] = value; db.collection('objects').update({_key:key}, {$set:data}, {upsert:true, w: 1}, function(err, result) { @@ -318,7 +321,7 @@ var _fields = {}; for(var i=0; i Date: Wed, 1 Jan 2014 14:15:53 -0500 Subject: [PATCH 2/4] thread delete restore fix --- src/postTools.js | 2 +- src/threadTools.js | 4 ++-- src/websockets.js | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/postTools.js b/src/postTools.js index 5af411e55e..37d1ac0a53 100644 --- a/src/postTools.js +++ b/src/postTools.js @@ -152,7 +152,7 @@ var winston = require('winston'), // Delete the thread if it is the last undeleted post threadTools.getLatestUndeletedPid(postData.tid, function(err, pid) { if (err && err.message === 'no-undeleted-pids-found') { - threadTools.delete(postData.tid, function(err) { + threadTools.delete(postData.tid, uid, function(err) { if (err) { winston.error('Could not delete topic (tid: ' + postData.tid + ')', err.stack); } diff --git a/src/threadTools.js b/src/threadTools.js index 859d6faac4..b69c42fa7c 100644 --- a/src/threadTools.js +++ b/src/threadTools.js @@ -91,7 +91,7 @@ var winston = require('winston'), } } - ThreadTools.delete = function(tid, callback) { + ThreadTools.delete = function(tid, uid, callback) { topics.delete(tid); db.decrObjectField('global', 'topicCount'); @@ -112,7 +112,7 @@ var winston = require('winston'), } } - ThreadTools.restore = function(tid, socket, callback) { + ThreadTools.restore = function(tid, uid, callback) { topics.restore(tid); db.incrObjectField('global', 'topicCount'); ThreadTools.unlock(tid); diff --git a/src/websockets.js b/src/websockets.js index b435d4b6ec..9682e6cfef 100644 --- a/src/websockets.js +++ b/src/websockets.js @@ -562,9 +562,10 @@ websockets.init = function(io) { socket.on('api:topic.delete', function(data) { threadTools.privileges(data.tid, uid, function(err, privileges) { if (!err && privileges.editable) { - threadTools.delete(data.tid, function(err) { + threadTools.delete(data.tid, uid, function(err) { if (!err) { emitTopicPostStats(); + events.logTopicDelete(uid, data.tid); socket.emit('api:topic.delete', { status: 'ok', tid: data.tid @@ -578,7 +579,7 @@ websockets.init = function(io) { socket.on('api:topic.restore', function(data) { threadTools.privileges(data.tid, uid, function(err, privileges) { if (!err && privileges.editable) { - threadTools.restore(data.tid, socket, function(err) { + threadTools.restore(data.tid, uid, function(err) { emitTopicPostStats(); socket.emit('api:topic.restore', { From 1996e64c9b47fd54f4fdeefae801e1ef8f2a969d Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Wed, 1 Jan 2014 14:38:12 -0500 Subject: [PATCH 3/4] if imgur client id is not set but local file uploads are enabled use that --- public/src/modules/composer.js | 3 +-- src/posts.js | 36 ++++++++++++++++++---------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/public/src/modules/composer.js b/public/src/modules/composer.js index 192a707142..f148dc2d49 100644 --- a/public/src/modules/composer.js +++ b/public/src/modules/composer.js @@ -94,9 +94,8 @@ define(['taskbar'], function(taskbar) { var postContainer = $(composerTemplate[0]); - if(config.imgurClientIDSet) { + if(config.allowFileUploads || config.imgurClientIDSet) initializeFileReader(post_uuid); - } var postData = composer.posts[post_uuid], titleEl = postContainer.find('.title'), diff --git a/src/posts.js b/src/posts.js index 0eb19b4a24..0ab4222321 100644 --- a/src/posts.js +++ b/src/posts.js @@ -360,24 +360,26 @@ var db = require('./database'), Posts.uploadPostImage = function(image, callback) { - if(!meta.config.imgurClientID) { - return callback('imgurClientID not set', null); - } + if(meta.config.imgurClientID) { + if(!image) { + return callback('invalid image', null); + } - if(!image) { - return callback('invalid image', null); + require('./imgur').upload(meta.config.imgurClientID, image.data, 'base64', function(err, data) { + if(err) { + callback(err.message, null); + } else { + callback(null, { + url: data.link, + name: image.name + }); + } + }); + } else if (meta.config.allowFileUploads) { + Posts.uploadPostFile(image, callback); + } else { + callback('Uploads are disabled!'); } - - require('./imgur').upload(meta.config.imgurClientID, image.data, 'base64', function(err, data) { - if(err) { - callback(err.message, null); - } else { - callback(null, { - url: data.link, - name: image.name - }); - } - }); } Posts.uploadPostFile = function(file, callback) { @@ -400,7 +402,7 @@ var db = require('./database'), var uploadPath = path.join(nconf.get('base_dir'), nconf.get('upload_path'), filename); fs.writeFile(uploadPath, buffer, function (err) { - if(err) { + if(err) { callback(err.message, null); } else { callback(null, { From d0e4689907b3dd2a217718ff90854b2c08528fa4 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Wed, 1 Jan 2014 14:44:15 -0500 Subject: [PATCH 4/4] removed extra event in websocket.js --- src/websockets.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/websockets.js b/src/websockets.js index 9682e6cfef..f6bf315df3 100644 --- a/src/websockets.js +++ b/src/websockets.js @@ -565,7 +565,6 @@ websockets.init = function(io) { threadTools.delete(data.tid, uid, function(err) { if (!err) { emitTopicPostStats(); - events.logTopicDelete(uid, data.tid); socket.emit('api:topic.delete', { status: 'ok', tid: data.tid