Merge branch 'master' of github.com:designcreateplay/NodeBB

v1.18.x
Julian Lam 11 years ago
commit 449adfae59

@ -94,9 +94,8 @@ define(['taskbar'], function(taskbar) {
var postContainer = $(composerTemplate[0]); var postContainer = $(composerTemplate[0]);
if(config.imgurClientIDSet) { if(config.allowFileUploads || config.imgurClientIDSet)
initializeFileReader(post_uuid); initializeFileReader(post_uuid);
}
var postData = composer.posts[post_uuid], var postData = composer.posts[post_uuid],
titleEl = postContainer.find('.title'), titleEl = postContainer.find('.title'),

@ -269,6 +269,9 @@
module.setObjectField = function(key, field, value, callback) { module.setObjectField = function(key, field, value, callback) {
var data = {}; var data = {};
// if there is a '.' in the field name it inserts subdocument in mongo, replace '.'s with \uff0E // 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'); field = field.replace(/\./g, '\uff0E');
data[field] = value; data[field] = value;
db.collection('objects').update({_key:key}, {$set:data}, {upsert:true, w: 1}, function(err, result) { db.collection('objects').update({_key:key}, {$set:data}, {upsert:true, w: 1}, function(err, result) {
@ -318,7 +321,7 @@
var _fields = {}; var _fields = {};
for(var i=0; i<fields.length; ++i) { for(var i=0; i<fields.length; ++i) {
if(typeof fields[i] !== string) { if(typeof fields[i] !== 'string') {
_fields[fields[i].toString().replace(/\./g, '\uff0E')] = 1; _fields[fields[i].toString().replace(/\./g, '\uff0E')] = 1;
} else { } else {
_fields[fields[i].replace(/\./g, '\uff0E')] = 1; _fields[fields[i].replace(/\./g, '\uff0E')] = 1;
@ -363,6 +366,9 @@
module.isObjectField = function(key, field, callback) { module.isObjectField = function(key, field, callback) {
var data = {}; var data = {};
if(typeof field !== 'string') {
field = field.toString();
}
field = field.replace(/\./g, '\uff0E'); field = field.replace(/\./g, '\uff0E');
data[field] = ''; data[field] = '';
db.collection('objects').findOne({_key:key}, {fields:data}, function(err, item) { db.collection('objects').findOne({_key:key}, {fields:data}, function(err, item) {
@ -375,6 +381,9 @@
module.deleteObjectField = function(key, field, callback) { module.deleteObjectField = function(key, field, callback) {
var data = {}; var data = {};
if(typeof field !== 'string') {
field = field.toString();
}
field = field.replace(/\./g, '\uff0E'); field = field.replace(/\./g, '\uff0E');
data[field] = ""; data[field] = "";
db.collection('objects').update({_key:key}, {$unset : data}, function(err, result) { db.collection('objects').update({_key:key}, {$unset : data}, function(err, result) {
@ -394,6 +403,9 @@
module.incrObjectFieldBy = function(key, field, value, callback) { module.incrObjectFieldBy = function(key, field, value, callback) {
var data = {}; var data = {};
if(typeof field !== 'string') {
field = field.toString();
}
field = field.replace(/\./g, '\uff0E'); field = field.replace(/\./g, '\uff0E');
data[field] = value; data[field] = value;
db.collection('objects').update({_key:key}, {$inc : data}, {upsert:true}, function(err, result) { db.collection('objects').update({_key:key}, {$inc : data}, {upsert:true}, function(err, result) {

@ -152,7 +152,7 @@ var winston = require('winston'),
// Delete the thread if it is the last undeleted post // Delete the thread if it is the last undeleted post
threadTools.getLatestUndeletedPid(postData.tid, function(err, pid) { threadTools.getLatestUndeletedPid(postData.tid, function(err, pid) {
if (err && err.message === 'no-undeleted-pids-found') { if (err && err.message === 'no-undeleted-pids-found') {
threadTools.delete(postData.tid, function(err) { threadTools.delete(postData.tid, uid, function(err) {
if (err) { if (err) {
winston.error('Could not delete topic (tid: ' + postData.tid + ')', err.stack); winston.error('Could not delete topic (tid: ' + postData.tid + ')', err.stack);
} }

@ -360,24 +360,26 @@ var db = require('./database'),
Posts.uploadPostImage = function(image, callback) { Posts.uploadPostImage = function(image, callback) {
if(!meta.config.imgurClientID) { if(meta.config.imgurClientID) {
return callback('imgurClientID not set', null); if(!image) {
} return callback('invalid image', null);
}
if(!image) { require('./imgur').upload(meta.config.imgurClientID, image.data, 'base64', function(err, data) {
return callback('invalid image', null); 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) { 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); var uploadPath = path.join(nconf.get('base_dir'), nconf.get('upload_path'), filename);
fs.writeFile(uploadPath, buffer, function (err) { fs.writeFile(uploadPath, buffer, function (err) {
if(err) { if(err) {
callback(err.message, null); callback(err.message, null);
} else { } else {
callback(null, { callback(null, {

@ -91,7 +91,7 @@ var winston = require('winston'),
} }
} }
ThreadTools.delete = function(tid, callback) { ThreadTools.delete = function(tid, uid, callback) {
topics.delete(tid); topics.delete(tid);
db.decrObjectField('global', 'topicCount'); 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); topics.restore(tid);
db.incrObjectField('global', 'topicCount'); db.incrObjectField('global', 'topicCount');
ThreadTools.unlock(tid); ThreadTools.unlock(tid);

@ -562,7 +562,7 @@ websockets.init = function(io) {
socket.on('api:topic.delete', function(data) { socket.on('api:topic.delete', function(data) {
threadTools.privileges(data.tid, uid, function(err, privileges) { threadTools.privileges(data.tid, uid, function(err, privileges) {
if (!err && privileges.editable) { if (!err && privileges.editable) {
threadTools.delete(data.tid, function(err) { threadTools.delete(data.tid, uid, function(err) {
if (!err) { if (!err) {
emitTopicPostStats(); emitTopicPostStats();
socket.emit('api:topic.delete', { socket.emit('api:topic.delete', {
@ -578,7 +578,7 @@ websockets.init = function(io) {
socket.on('api:topic.restore', function(data) { socket.on('api:topic.restore', function(data) {
threadTools.privileges(data.tid, uid, function(err, privileges) { threadTools.privileges(data.tid, uid, function(err, privileges) {
if (!err && privileges.editable) { if (!err && privileges.editable) {
threadTools.restore(data.tid, socket, function(err) { threadTools.restore(data.tid, uid, function(err) {
emitTopicPostStats(); emitTopicPostStats();
socket.emit('api:topic.restore', { socket.emit('api:topic.restore', {

Loading…
Cancel
Save