mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-30 18:46:01 +01:00
Merge branch 'master' of github.com:designcreateplay/NodeBB
This commit is contained in:
1
app.js
1
app.js
@@ -74,6 +74,7 @@
|
|||||||
nconf.set('upload_url', path.join(path.sep, nconf.get('relative_path'), 'uploads', path.sep));
|
nconf.set('upload_url', path.join(path.sep, nconf.get('relative_path'), 'uploads', path.sep));
|
||||||
nconf.set('base_dir', __dirname);
|
nconf.set('base_dir', __dirname);
|
||||||
|
|
||||||
|
winston.info('Time: ' + new Date());
|
||||||
winston.info('Initializing NodeBB v' + pkg.version + ', on port ' + nconf.get('port') + ', using ' + nconf.get('database') +' store at ' + nconf.get(nconf.get('database') + ':host') + ':' + nconf.get(nconf.get('database') + ':port') + '.');
|
winston.info('Initializing NodeBB v' + pkg.version + ', on port ' + nconf.get('port') + ', using ' + nconf.get('database') +' store at ' + nconf.get(nconf.get('database') + ':host') + ':' + nconf.get(nconf.get('database') + ':port') + '.');
|
||||||
winston.info('NodeBB instance bound to: ' + ((nconf.get('bind_address') === "0.0.0.0" || !nconf.get('bind_address')) ? 'Any address (0.0.0.0)' : nconf.get('bind_address')));
|
winston.info('NodeBB instance bound to: ' + ((nconf.get('bind_address') === "0.0.0.0" || !nconf.get('bind_address')) ? 'Any address (0.0.0.0)' : nconf.get('bind_address')));
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,12 @@ var ajaxify = {};
|
|||||||
ajaxify.currentPage = null;
|
ajaxify.currentPage = null;
|
||||||
|
|
||||||
ajaxify.go = function (url, callback, quiet) {
|
ajaxify.go = function (url, callback, quiet) {
|
||||||
|
if ($('#content').hasClass('ajaxifying')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
jQuery('#footer, #content').addClass('ajaxifying');
|
||||||
|
|
||||||
// start: the following should be set like so: ajaxify.onchange(function(){}); where the code actually belongs
|
// start: the following should be set like so: ajaxify.onchange(function(){}); where the code actually belongs
|
||||||
$(window).off('scroll');
|
$(window).off('scroll');
|
||||||
app.enterRoom('global');
|
app.enterRoom('global');
|
||||||
@@ -48,9 +54,6 @@ var ajaxify = {};
|
|||||||
window.onscroll = null;
|
window.onscroll = null;
|
||||||
// end
|
// end
|
||||||
|
|
||||||
if ($('#content').hasClass('ajaxifying')) {
|
|
||||||
templates.cancelRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove trailing slash
|
// Remove trailing slash
|
||||||
url = url.replace(/\/$/, "");
|
url = url.replace(/\/$/, "");
|
||||||
@@ -98,11 +101,12 @@ var ajaxify = {};
|
|||||||
|
|
||||||
translator.load(tpl_url);
|
translator.load(tpl_url);
|
||||||
|
|
||||||
jQuery('#footer, #content').removeClass('hide').addClass('ajaxifying');
|
jQuery('#footer, #content').removeClass('hide');
|
||||||
|
|
||||||
templates.flush();
|
templates.flush();
|
||||||
templates.load_template(function () {
|
templates.load_template(function () {
|
||||||
exec_body_scripts(content);
|
exec_body_scripts(content);
|
||||||
|
|
||||||
require(['forum/' + tpl_url], function(script) {
|
require(['forum/' + tpl_url], function(script) {
|
||||||
if (script && script.init) {
|
if (script && script.init) {
|
||||||
script.init();
|
script.init();
|
||||||
@@ -172,7 +176,6 @@ var ajaxify = {};
|
|||||||
var url = this.href.replace(rootUrl + '/', '');
|
var url = this.href.replace(rootUrl + '/', '');
|
||||||
|
|
||||||
if (ajaxify.go(url)) {
|
if (ajaxify.go(url)) {
|
||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
} else if (window.location.pathname !== '/outgoing') {
|
} else if (window.location.pathname !== '/outgoing') {
|
||||||
|
|||||||
@@ -127,16 +127,16 @@ define(function() {
|
|||||||
foundUserLabel = foundUser.getElementsByTagName('span')[0];
|
foundUserLabel = foundUser.getElementsByTagName('span')[0];
|
||||||
|
|
||||||
socket.emit('admin.user.search', searchText, function(err, results) {
|
socket.emit('admin.user.search', searchText, function(err, results) {
|
||||||
if (!err && results && results.length > 0) {
|
if (!err && results && results.users.length > 0) {
|
||||||
var numResults = results.length,
|
var numResults = results.users.length,
|
||||||
resultsSlug = document.createDocumentFragment(),
|
resultsSlug = document.createDocumentFragment(),
|
||||||
x;
|
x;
|
||||||
if (numResults > 4) numResults = 4;
|
if (numResults > 4) numResults = 4;
|
||||||
for (x = 0; x < numResults; x++) {
|
for (x = 0; x < numResults; x++) {
|
||||||
foundUserImg.src = results[x].picture;
|
foundUserImg.src = results.users[x].picture;
|
||||||
foundUserLabel.innerHTML = results[x].username;
|
foundUserLabel.innerHTML = results.users[x].username;
|
||||||
foundUser.setAttribute('title', results[x].username);
|
foundUser.setAttribute('title', results.users[x].username);
|
||||||
foundUser.setAttribute('data-uid', results[x].uid);
|
foundUser.setAttribute('data-uid', results.users[x].uid);
|
||||||
resultsSlug.appendChild(foundUser.cloneNode(true));
|
resultsSlug.appendChild(foundUser.cloneNode(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,7 +172,7 @@ define(function() {
|
|||||||
groupMembersEl.on('click', 'li[data-uid]', function() {
|
groupMembersEl.on('click', 'li[data-uid]', function() {
|
||||||
var uid = this.getAttribute('data-uid'),
|
var uid = this.getAttribute('data-uid'),
|
||||||
gid = detailsModal.attr('data-gid');
|
gid = detailsModal.attr('data-gid');
|
||||||
|
|
||||||
socket.emit('admin.groups.get', gid, function(err, groupObj){
|
socket.emit('admin.groups.get', gid, function(err, groupObj){
|
||||||
if (!err){
|
if (!err){
|
||||||
if (groupObj.name == 'Administrators' && uid == yourid){
|
if (groupObj.name == 'Administrators' && uid == yourid){
|
||||||
|
|||||||
@@ -196,23 +196,23 @@ define(function() {
|
|||||||
socket.emit('admin.user.search', username, function(err, data) {
|
socket.emit('admin.user.search', username, function(err, data) {
|
||||||
if(err) {
|
if(err) {
|
||||||
return app.alertError(err.message);
|
return app.alertError(err.message);
|
||||||
}console.log(data)
|
}
|
||||||
|
|
||||||
var html = templates.prepare(templates['admin/users'].blocks['users']).parse({
|
var html = templates.prepare(templates['admin/users'].blocks['users']).parse({
|
||||||
users: data
|
users: data.users
|
||||||
}),
|
}),
|
||||||
userListEl = document.querySelector('.users');
|
userListEl = document.querySelector('.users');
|
||||||
|
|
||||||
userListEl.innerHTML = html;
|
userListEl.innerHTML = html;
|
||||||
jQuery('.fa-spinner').addClass('none');
|
jQuery('.fa-spinner').addClass('none');
|
||||||
|
|
||||||
if (data && data.length === 0) {
|
if (data && data.users.length === 0) {
|
||||||
$('#user-notfound-notify').html('User not found!')
|
$('#user-notfound-notify').html('User not found!')
|
||||||
.show()
|
.show()
|
||||||
.addClass('label-danger')
|
.addClass('label-danger')
|
||||||
.removeClass('label-success');
|
.removeClass('label-success');
|
||||||
} else {
|
} else {
|
||||||
$('#user-notfound-notify').html(data.length + ' user' + (data.length > 1 ? 's' : '') + ' found!')
|
$('#user-notfound-notify').html(data.users.length + ' user' + (data.users.length > 1 ? 's' : '') + ' found! Search took ' + data.timing + ' ms.')
|
||||||
.show()
|
.show()
|
||||||
.addClass('label-success')
|
.addClass('label-success')
|
||||||
.removeClass('label-danger');
|
.removeClass('label-danger');
|
||||||
|
|||||||
@@ -91,6 +91,7 @@ define(function() {
|
|||||||
html = $(translatedHTML);
|
html = $(translatedHTML);
|
||||||
container.append(html);
|
container.append(html);
|
||||||
$('span.timeago').timeago();
|
$('span.timeago').timeago();
|
||||||
|
app.createUserTooltips();
|
||||||
app.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
app.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -366,6 +366,7 @@ define(['composer'], function(composer) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$('.topic').on('click', '.post_reply', function() {
|
$('.topic').on('click', '.post_reply', function() {
|
||||||
var selectionText = '',
|
var selectionText = '',
|
||||||
selection = window.getSelection() || document.getSelection();
|
selection = window.getSelection() || document.getSelection();
|
||||||
@@ -1110,6 +1111,7 @@ define(['composer'], function(composer) {
|
|||||||
infiniteLoaderActive = false;
|
infiniteLoaderActive = false;
|
||||||
|
|
||||||
app.populateOnlineUsers();
|
app.populateOnlineUsers();
|
||||||
|
app.createUserTooltips();
|
||||||
app.addCommasToNumbers();
|
app.addCommasToNumbers();
|
||||||
$('span.timeago').timeago();
|
$('span.timeago').timeago();
|
||||||
$('.post-content img').addClass('img-responsive');
|
$('.post-content img').addClass('img-responsive');
|
||||||
@@ -1139,7 +1141,7 @@ define(['composer'], function(composer) {
|
|||||||
$('#topic-post-count').html(Topic.postCount);
|
$('#topic-post-count').html(Topic.postCount);
|
||||||
updateHeader();
|
updateHeader();
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadMorePosts(tid, callback) {
|
function loadMorePosts(tid, callback) {
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ define(function() {
|
|||||||
html = $(translatedHTML);
|
html = $(translatedHTML);
|
||||||
container.append(html);
|
container.append(html);
|
||||||
$('span.timeago').timeago();
|
$('span.timeago').timeago();
|
||||||
|
app.createUserTooltips();
|
||||||
app.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
app.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,8 @@ define(function() {
|
|||||||
return app.alert(err.message);
|
return app.alert(err.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(data);
|
||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
$('#user-notfound-notify').html('You need to be logged in to search!');
|
$('#user-notfound-notify').html('You need to be logged in to search!');
|
||||||
$('#user-notfound-notify').parent().addClass('btn-warning label-warning');
|
$('#user-notfound-notify').parent().addClass('btn-warning label-warning');
|
||||||
@@ -59,18 +61,18 @@ define(function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var html = templates.prepare(templates['users'].blocks['users']).parse({
|
var html = templates.prepare(templates['users'].blocks['users']).parse({
|
||||||
users: data
|
users: data.users
|
||||||
}),
|
}),
|
||||||
userListEl = $('#users-container');
|
userListEl = $('#users-container');
|
||||||
|
|
||||||
userListEl.html(html);
|
userListEl.html(html);
|
||||||
|
|
||||||
|
|
||||||
if (data && data.length === 0) {
|
if (data && data.users.length === 0) {
|
||||||
$('#user-notfound-notify').html('User not found!');
|
$('#user-notfound-notify').html('User not found!');
|
||||||
$('#user-notfound-notify').parent().addClass('btn-warning label-warning');
|
$('#user-notfound-notify').parent().addClass('btn-warning label-warning');
|
||||||
} else {
|
} else {
|
||||||
$('#user-notfound-notify').html(data.length + ' user' + (data.length > 1 ? 's' : '') + ' found!');
|
$('#user-notfound-notify').html(data.users.length + ' user' + (data.users.length > 1 ? 's' : '') + ' found! Search took ' + data.timing + ' ms.');
|
||||||
$('#user-notfound-notify').parent().addClass('btn-success label-success');
|
$('#user-notfound-notify').parent().addClass('btn-success label-success');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -343,6 +343,20 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.getObjectKeys = function(key, callback) {
|
||||||
|
module.getObject(key, function(err, data) {
|
||||||
|
if(err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(data) {
|
||||||
|
callback(null, Object.keys(data));
|
||||||
|
} else {
|
||||||
|
callback(null, []);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
module.getObjectValues = function(key, callback) {
|
module.getObjectValues = function(key, callback) {
|
||||||
module.getObject(key, function(err, data) {
|
module.getObject(key, function(err, data) {
|
||||||
if(err) {
|
if(err) {
|
||||||
|
|||||||
@@ -275,6 +275,10 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.getObjectKeys = function(key, callback) {
|
||||||
|
redisClient.hkeys(key, callback);
|
||||||
|
}
|
||||||
|
|
||||||
module.getObjectValues = function(key, callback) {
|
module.getObjectValues = function(key, callback) {
|
||||||
redisClient.hvals(key, callback);
|
redisClient.hvals(key, callback);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,12 +26,6 @@ var async = require('async'),
|
|||||||
'default': (nconf.get('use_port') !== undefined ? (nconf.get('use_port') ? 'y' : 'n') : 'y'),
|
'default': (nconf.get('use_port') !== undefined ? (nconf.get('use_port') ? 'y' : 'n') : 'y'),
|
||||||
pattern: /y[es]*|n[o]?/,
|
pattern: /y[es]*|n[o]?/,
|
||||||
message: 'Please enter \'yes\' or \'no\''
|
message: 'Please enter \'yes\' or \'no\''
|
||||||
}, {
|
|
||||||
name: 'use_proxy',
|
|
||||||
description: 'is NodeBB behind a proxy?',
|
|
||||||
'default': (nconf.get('use_proxy') !== undefined ? (nconf.get('use_proxy') ? 'y' : 'n') : 'y'),
|
|
||||||
pattern: /y[es]*|n[o]?/,
|
|
||||||
message: 'Please enter \'yes\' or \'no\''
|
|
||||||
}, {
|
}, {
|
||||||
name: 'secret',
|
name: 'secret',
|
||||||
description: 'Please enter a NodeBB secret',
|
description: 'Please enter a NodeBB secret',
|
||||||
@@ -147,7 +141,6 @@ var async = require('async'),
|
|||||||
config.bcrypt_rounds = 12;
|
config.bcrypt_rounds = 12;
|
||||||
config.upload_path = '/public/uploads';
|
config.upload_path = '/public/uploads';
|
||||||
config.use_port = config.use_port.slice(0, 1) === 'y';
|
config.use_port = config.use_port.slice(0, 1) === 'y';
|
||||||
config.use_proxy = config.use_proxy.slice(0, 1) === 'y';
|
|
||||||
|
|
||||||
var urlObject = url.parse(config.base_url),
|
var urlObject = url.parse(config.base_url),
|
||||||
relative_path = (urlObject.pathname && urlObject.pathname.length > 1) ? urlObject.pathname : '',
|
relative_path = (urlObject.pathname && urlObject.pathname.length > 1) ? urlObject.pathname : '',
|
||||||
|
|||||||
17
src/posts.js
17
src/posts.js
@@ -439,26 +439,23 @@ var db = require('./database'),
|
|||||||
|
|
||||||
Posts.reIndexPids = function(pids, callback) {
|
Posts.reIndexPids = function(pids, callback) {
|
||||||
|
|
||||||
function reIndex(pid, callback) {
|
function reIndex(pid, next) {
|
||||||
|
|
||||||
Posts.getPostField(pid, 'content', function(err, content) {
|
Posts.getPostField(pid, 'content', function(err, content) {
|
||||||
db.searchRemove('post', pid, function() {
|
if(err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
db.searchRemove('post', pid, function() {
|
||||||
if (content && content.length) {
|
if (content && content.length) {
|
||||||
db.searchIndex('post', content, pid);
|
db.searchIndex('post', content, pid);
|
||||||
}
|
}
|
||||||
callback(null);
|
next();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async.each(pids, reIndex, function(err) {
|
async.each(pids, reIndex, callback);
|
||||||
if (err) {
|
|
||||||
callback(err, null);
|
|
||||||
} else {
|
|
||||||
callback(null, 'Posts reindexed');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Posts.getFavourites = function(uid, callback) {
|
Posts.getFavourites = function(uid, callback) {
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ SocketAdmin.user.search = function(socket, username, callback) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async.each(data, isAdmin, function(err) {
|
async.each(data.users, isAdmin, function(err) {
|
||||||
callback(err, data);
|
callback(err, data);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -126,7 +126,7 @@ SocketAdmin.categories.search = function(socket, data, callback) {
|
|||||||
cid = data.cid;
|
cid = data.cid;
|
||||||
|
|
||||||
user.search(username, function(err, data) {
|
user.search(username, function(err, data) {
|
||||||
async.map(data, function(userObj, next) {
|
async.map(data.users, function(userObj, next) {
|
||||||
CategoryTools.privileges(cid, userObj.uid, function(err, privileges) {
|
CategoryTools.privileges(cid, userObj.uid, function(err, privileges) {
|
||||||
if(err) {
|
if(err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
|
|||||||
201
src/topics.js
201
src/topics.js
@@ -53,7 +53,6 @@ var async = require('async'),
|
|||||||
|
|
||||||
user.addTopicIdToUser(uid, tid, timestamp);
|
user.addTopicIdToUser(uid, tid, timestamp);
|
||||||
|
|
||||||
// in future it may be possible to add topics to several categories, so leaving the door open here.
|
|
||||||
db.sortedSetAdd('categories:' + cid + ':tid', timestamp, tid);
|
db.sortedSetAdd('categories:' + cid + ':tid', timestamp, tid);
|
||||||
db.incrObjectField('category:' + cid, 'topic_count');
|
db.incrObjectField('category:' + cid, 'topic_count');
|
||||||
db.incrObjectField('global', 'topicCount');
|
db.incrObjectField('global', 'topicCount');
|
||||||
@@ -66,75 +65,65 @@ var async = require('async'),
|
|||||||
};
|
};
|
||||||
|
|
||||||
Topics.post = function(uid, title, content, cid, callback) {
|
Topics.post = function(uid, title, content, cid, callback) {
|
||||||
|
if (title) {
|
||||||
|
title = title.trim();
|
||||||
|
}
|
||||||
|
|
||||||
categoryTools.privileges(cid, uid, function(err, privileges) {
|
if (!title || title.length < parseInt(meta.config.minimumTitleLength, 10)) {
|
||||||
|
return callback(new Error('title-too-short'));
|
||||||
|
} else if(title.length > parseInt(meta.config.maximumTitleLength, 10)) {
|
||||||
|
return callback(new Error('title-too-long'));
|
||||||
|
}
|
||||||
|
|
||||||
if(err) {
|
if (content) {
|
||||||
return callback(err);
|
content = content.trim();
|
||||||
} else if(!privileges.write) {
|
}
|
||||||
return callback(new Error('no-privileges'));
|
|
||||||
} else if (!cid) {
|
|
||||||
return callback(new Error('invalid-cid'));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (title) {
|
if (!content || content.length < meta.config.miminumPostLength) {
|
||||||
title = title.trim();
|
return callback(new Error('content-too-short'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!title || title.length < parseInt(meta.config.minimumTitleLength, 10)) {
|
if (!cid) {
|
||||||
return callback(new Error('title-too-short'), null);
|
return callback(new Error('invalid-cid'));
|
||||||
} else if(title.length > parseInt(meta.config.maximumTitleLength, 10)) {
|
}
|
||||||
return callback(new Error('title-too-long'), null);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (content) {
|
async.waterfall([
|
||||||
content = content.trim();
|
function(next) {
|
||||||
}
|
categoryTools.privileges(cid, uid, next);
|
||||||
|
},
|
||||||
if (!content || content.length < meta.config.miminumPostLength) {
|
function(privileges, next) {
|
||||||
return callback(new Error('content-too-short'), null);
|
if(!privileges.write) {
|
||||||
}
|
return next(new Error('no-privileges'));
|
||||||
|
|
||||||
user.getUserField(uid, 'lastposttime', function(err, lastposttime) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
}
|
||||||
|
next();
|
||||||
if(!lastposttime) {
|
},
|
||||||
lastposttime = 0;
|
function(next) {
|
||||||
}
|
user.isReadyToPost(uid, next);
|
||||||
|
},
|
||||||
if (Date.now() - lastposttime < meta.config.postDelay * 1000) {
|
function(next) {
|
||||||
return callback(new Error('too-many-posts'), null);
|
Topics.create(uid, title, cid, next);
|
||||||
}
|
},
|
||||||
|
function(tid, next) {
|
||||||
Topics.create(uid, title, cid, function(err, tid) {
|
Topics.reply(tid, uid, content, next);
|
||||||
|
},
|
||||||
|
function(postData, next) {
|
||||||
|
threadTools.toggleFollow(postData.tid, uid);
|
||||||
|
next(null, postData);
|
||||||
|
},
|
||||||
|
function(postData, next) {
|
||||||
|
Topics.getTopicForCategoryView(postData.tid, uid, function(err, topicData) {
|
||||||
if(err) {
|
if(err) {
|
||||||
return callback(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
Topics.reply(tid, uid, content, function(err, postData) {
|
topicData.unreplied = 1;
|
||||||
|
next(null, {
|
||||||
if(err) {
|
topicData: topicData,
|
||||||
return callback(err, null);
|
postData: postData
|
||||||
} else if(!postData) {
|
|
||||||
return callback(new Error('invalid-post'), null);
|
|
||||||
}
|
|
||||||
|
|
||||||
threadTools.toggleFollow(tid, uid);
|
|
||||||
|
|
||||||
Topics.getTopicForCategoryView(tid, uid, function(topicData) {
|
|
||||||
topicData.unreplied = 1;
|
|
||||||
|
|
||||||
callback(null, {
|
|
||||||
topicData: topicData,
|
|
||||||
postData: postData
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
});
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
Topics.reply = function(tid, uid, content, callback) {
|
Topics.reply = function(tid, uid, content, callback) {
|
||||||
@@ -152,18 +141,7 @@ var async = require('async'),
|
|||||||
next();
|
next();
|
||||||
},
|
},
|
||||||
function(next) {
|
function(next) {
|
||||||
user.getUserField(uid, 'lastposttime', next);
|
user.isReadyToPost(uid, next);
|
||||||
},
|
|
||||||
function(lastposttime, next) {
|
|
||||||
if(!lastposttime) {
|
|
||||||
lastposttime = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Date.now() - parseInt(lastposttime, 10) < parseInt(meta.config.postDelay, 10) * 1000) {
|
|
||||||
return next(new Error('too-many-posts'), null);
|
|
||||||
}
|
|
||||||
|
|
||||||
next();
|
|
||||||
},
|
},
|
||||||
function(next) {
|
function(next) {
|
||||||
if (content) {
|
if (content) {
|
||||||
@@ -235,41 +213,40 @@ var async = require('async'),
|
|||||||
pids.sort();
|
pids.sort();
|
||||||
var mainPid = pids[0];
|
var mainPid = pids[0];
|
||||||
|
|
||||||
posts.getPostData(mainPid, function(err, postData) {
|
async.parallel({
|
||||||
if(err) {
|
postData: function(callback) {
|
||||||
return callback(err);
|
posts.getPostData(mainPid, callback);
|
||||||
|
},
|
||||||
|
cid: function(callback) {
|
||||||
|
posts.getCidByPid(mainPid, callback);
|
||||||
}
|
}
|
||||||
|
}, function(err, results) {
|
||||||
posts.getCidByPid(mainPid, function(err, cid) {
|
Topics.create(results.postData.uid, title, results.cid, function(err, tid) {
|
||||||
if(err) {
|
if(err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
Topics.create(postData.uid, title, cid, function(err, tid) {
|
async.eachSeries(pids, move, function(err) {
|
||||||
if(err) {
|
if(err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
async.eachSeries(pids, move, function(err) {
|
Topics.getTopicData(tid, callback);
|
||||||
|
});
|
||||||
|
|
||||||
|
function move(pid, next) {
|
||||||
|
postTools.privileges(pid, uid, function(err, privileges) {
|
||||||
if(err) {
|
if(err) {
|
||||||
return callback(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
Topics.getTopicData(tid, function(err, topicData) {
|
if(privileges.editable) {
|
||||||
callback(err, topicData);
|
Topics.movePostToTopic(pid, tid, next);
|
||||||
});
|
} else {
|
||||||
|
next();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
function move(pid, next) {
|
|
||||||
postTools.privileges(pid, uid, function(err, privileges) {
|
|
||||||
if(privileges.editable) {
|
|
||||||
Topics.movePostToTopic(pid, tid, next);
|
|
||||||
} else {
|
|
||||||
next();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -418,6 +395,10 @@ var async = require('async'),
|
|||||||
|
|
||||||
Topics.getCategoryData = function(tid, callback) {
|
Topics.getCategoryData = function(tid, callback) {
|
||||||
Topics.getTopicField(tid, 'cid', function(err, cid) {
|
Topics.getTopicField(tid, 'cid', function(err, cid) {
|
||||||
|
if(err) {
|
||||||
|
callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
categories.getCategoryData(cid, callback);
|
categories.getCategoryData(cid, callback);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -838,15 +819,12 @@ var async = require('async'),
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getTeaser(next) {
|
function getTeaser(next) {
|
||||||
Topics.getTeaser(tid, function(err, teaser) {
|
Topics.getTeaser(tid, next);
|
||||||
if (err) teaser = {};
|
|
||||||
next(null, teaser);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async.parallel([getTopicData, getReadStatus, getTeaser], function(err, results) {
|
async.parallel([getTopicData, getReadStatus, getTeaser], function(err, results) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw new Error(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
var topicData = results[0],
|
var topicData = results[0],
|
||||||
@@ -863,7 +841,7 @@ var async = require('async'),
|
|||||||
topicData.teaser_timestamp = utils.toISOString(teaser.timestamp);
|
topicData.teaser_timestamp = utils.toISOString(teaser.timestamp);
|
||||||
topicData.teaser_userpicture = teaser.picture;
|
topicData.teaser_userpicture = teaser.picture;
|
||||||
|
|
||||||
callback(topicData);
|
callback(null, topicData);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1151,33 +1129,20 @@ var async = require('async'),
|
|||||||
Topics.reIndexTopic = function(tid, callback) {
|
Topics.reIndexTopic = function(tid, callback) {
|
||||||
Topics.getPids(tid, function(err, pids) {
|
Topics.getPids(tid, function(err, pids) {
|
||||||
if (err) {
|
if (err) {
|
||||||
callback(err);
|
return callback(err);
|
||||||
} else {
|
|
||||||
posts.reIndexPids(pids, function(err) {
|
|
||||||
if (err) {
|
|
||||||
callback(err);
|
|
||||||
} else {
|
|
||||||
callback(null);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
posts.reIndexPids(pids, callback);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Topics.reIndexAll = function(callback) {
|
Topics.reIndexAll = function(callback) {
|
||||||
db.getSetMembers('topics:tid', function(err, tids) {
|
db.getSetMembers('topics:tid', function(err, tids) {
|
||||||
if (err) {
|
if (err) {
|
||||||
callback(err, null);
|
return callback(err);
|
||||||
} else {
|
|
||||||
|
|
||||||
async.each(tids, Topics.reIndexTopic, function(err) {
|
|
||||||
if (err) {
|
|
||||||
callback(err, null);
|
|
||||||
} else {
|
|
||||||
callback(null, 'All topics reindexed.');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async.each(tids, Topics.reIndexTopic, callback);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
49
src/user.js
49
src/user.js
@@ -348,6 +348,23 @@ var bcrypt = require('bcrypt'),
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
User.isReadyToPost = function(uid, callback) {
|
||||||
|
User.getUserField(uid, 'lastposttime', function(err, lastposttime) {
|
||||||
|
if(err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!lastposttime) {
|
||||||
|
lastposttime = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Date.now() - parseInt(lastposttime, 10) < parseInt(meta.config.postDelay, 10) * 1000) {
|
||||||
|
return callback(new Error('too-many-posts'));
|
||||||
|
}
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
User.isEmailAvailable = function(email, callback) {
|
User.isEmailAvailable = function(email, callback) {
|
||||||
db.isObjectField('email:uid', email, function(err, exists) {
|
db.isObjectField('email:uid', email, function(err, exists) {
|
||||||
callback(err, !exists);
|
callback(err, !exists);
|
||||||
@@ -473,34 +490,36 @@ var bcrypt = require('bcrypt'),
|
|||||||
|
|
||||||
User.search = function(query, callback) {
|
User.search = function(query, callback) {
|
||||||
if (!query || query.length === 0) {
|
if (!query || query.length === 0) {
|
||||||
return callback(null, []);
|
return callback(null, {timing:0, users:[]});
|
||||||
}
|
}
|
||||||
|
var start = process.hrtime();
|
||||||
|
|
||||||
// TODO: Have this use db.getObjectKeys (doesn't exist yet)
|
|
||||||
db.getObject('username:uid', function(err, usernamesHash) {
|
db.getObject('username:uid', function(err, usernamesHash) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(null, []);
|
return callback(null, {timing: 0, users:[]});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
query = query.toLowerCase();
|
||||||
|
|
||||||
var usernames = Object.keys(usernamesHash),
|
var usernames = Object.keys(usernamesHash),
|
||||||
results = [];
|
results = [];
|
||||||
|
|
||||||
results = usernames.filter(function(username) { // Remove non-matches
|
results = usernames.filter(function(username) {
|
||||||
return username.indexOf(query) === 0;
|
return username.toLowerCase().indexOf(query) === 0;
|
||||||
}).sort(function(a, b) { // Sort alphabetically
|
})
|
||||||
|
.slice(0, 10)
|
||||||
|
.sort(function(a, b) {
|
||||||
return a > b;
|
return a > b;
|
||||||
}).slice(0, 5) // Limit 5
|
})
|
||||||
.map(function(username) { // Translate to uids
|
.map(function(username) {
|
||||||
return usernamesHash[username];
|
return usernamesHash[username];
|
||||||
});
|
});
|
||||||
|
|
||||||
if (results && results.length) {
|
User.getDataForUsers(results, function(userdata) {
|
||||||
User.getDataForUsers(results, function(userdata) {
|
var diff = process.hrtime(start);
|
||||||
callback(null, userdata);
|
var timing = (diff[0] * 1e3 + diff[1] / 1e6).toFixed(1);
|
||||||
});
|
callback(null, {timing: timing, users: userdata});
|
||||||
} else {
|
});
|
||||||
callback(null, []);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -191,23 +191,11 @@ if(nconf.get('ssl')) {
|
|||||||
|
|
||||||
app.use(express.csrf());
|
app.use(express.csrf());
|
||||||
|
|
||||||
// negative boolean with type check here to support a config.json without a 'use_proxy' value,
|
if (nconf.get('port') != 80 && nconf.get('port') != 443 && nconf.get('use_port') === true) {
|
||||||
// so unless it's specifically set to false, it's true (as long as it's not a dev env)
|
winston.info('Enabling \'trust proxy\'');
|
||||||
// todo: remove double negative with a minor release, where backward compatibility can be broken
|
|
||||||
// and if dev mode, then it's probably not behind a proxy but it can be forced by setting 'use_proxy' to true
|
|
||||||
|
|
||||||
if (nconf.get('use_proxy') === false) {
|
|
||||||
winston.info('\'use_proxy\' is set to false in config file, skipping \'trust proxy\'');
|
|
||||||
|
|
||||||
} else if (!nconf.get('use_proxy') && process.env.NODE_ENV === 'development') {
|
|
||||||
winston.info('\'use_proxy\' is not set, skipping because you\'re in development env. Set to true to force enabling it.');
|
|
||||||
|
|
||||||
} else {
|
|
||||||
winston.info('\'use_proxy\''
|
|
||||||
+ (nconf.get('use_proxy') === true ? ' is set to true ' : ' is not set ')
|
|
||||||
+ 'in config file, enabling \'trust proxy\', set to false to disable it.');
|
|
||||||
|
|
||||||
app.enable('trust proxy');
|
app.enable('trust proxy');
|
||||||
|
} else if (process.env.NODE_ENV !== 'development') {
|
||||||
|
winston.info('Using ports 80 and 443 is not recommend; use a proxy instead. See README.md');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Local vars, other assorted setup
|
// Local vars, other assorted setup
|
||||||
@@ -401,7 +389,7 @@ if(nconf.get('ssl')) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
plugins.fireHook('action:app.load');
|
plugins.fireHook('action:app.load', app);
|
||||||
|
|
||||||
translator.translate(templates.logout.toString(), function(parsedTemplate) {
|
translator.translate(templates.logout.toString(), function(parsedTemplate) {
|
||||||
templates.logout = parsedTemplate;
|
templates.logout = parsedTemplate;
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
// this test currently needs to talk to the redis database.
|
|
||||||
// get the redis config info from root directory's config.json:
|
|
||||||
var winston = require('winston');
|
var winston = require('winston');
|
||||||
|
|
||||||
process.on('uncaughtException', function (err) {
|
process.on('uncaughtException', function (err) {
|
||||||
@@ -59,4 +58,4 @@ describe('Categories', function() {
|
|||||||
db.delete('category:' + categoryObj.cid);
|
db.delete('category:' + categoryObj.cid);
|
||||||
db.listRemoveLast('categories:cid');
|
db.listRemoveLast('categories:cid');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -73,6 +73,12 @@ describe('Test database', function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getObjectKeys(callback) {
|
||||||
|
db.getObjectKeys(objectKey, function(err, data) {
|
||||||
|
callback(err, {'getObjectKeys':data});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
var objectTasks = [
|
var objectTasks = [
|
||||||
setObject,
|
setObject,
|
||||||
getObject,
|
getObject,
|
||||||
@@ -88,7 +94,8 @@ describe('Test database', function() {
|
|||||||
isObjectField,
|
isObjectField,
|
||||||
incrObjectFieldBy,
|
incrObjectFieldBy,
|
||||||
getObject,
|
getObject,
|
||||||
getObjects
|
getObjects,
|
||||||
|
getObjectKeys
|
||||||
];
|
];
|
||||||
|
|
||||||
async.series(objectTasks, function(err, results) {
|
async.series(objectTasks, function(err, results) {
|
||||||
|
|||||||
Reference in New Issue
Block a user