From 46afbc0ba08add68e63d320bfc53ea9a1d779765 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Mon, 12 Aug 2013 19:00:31 -0400 Subject: [PATCH] assorted config fixes --- app.js | 1 - public/src/modules/composer.js | 8 ++++---- src/install.js | 5 ++++- src/posts.js | 13 ++++++------- src/topics.js | 11 ++++++----- src/websockets.js | 4 ++-- 6 files changed, 22 insertions(+), 20 deletions(-) diff --git a/app.js b/app.js index f9c2ab523b..d445069f95 100644 --- a/app.js +++ b/app.js @@ -16,7 +16,6 @@ along with this program. If not, see . */ -// Read config.js to grab redis info var fs = require('fs'), nconf = require('nconf'), pkg = require('./package.json'), diff --git a/public/src/modules/composer.js b/public/src/modules/composer.js index 1d00f68172..1f8235b9c0 100644 --- a/public/src/modules/composer.js +++ b/public/src/modules/composer.js @@ -299,22 +299,22 @@ define(['taskbar'], function(taskbar) { titleEl.value = titleEl.value.trim(); bodyEl.value = bodyEl.value.trim(); - if (titleEl.value.length < 3) { + if (titleEl.value.length < config.minimumTitleLength) { return app.alert({ type: 'error', timeout: 2000, title: 'Title too short', - message: "Please enter a longer title. At least 3 characters.", + message: "Please enter a longer title. At least " + config.minimumTitleLength+ " characters.", alert_id: 'post_error' }); } - if (bodyEl.value.length < 8) { + if (bodyEl.value.length < config.minimumPostLength) { return app.alert({ type: 'error', timeout: 2000, title: 'Content too short', - message: "Please enter a longer post. At least 8 characters.", + message: "Please enter a longer post. At least " + config.minimumPostLength + " characters.", alert_id: 'post_error' }); } diff --git a/src/install.js b/src/install.js index c9301ee8f1..7d3094e0c4 100644 --- a/src/install.js +++ b/src/install.js @@ -78,12 +78,15 @@ var async = require('async'), port: config.port }, api_url: protocol + '//' + host + (config.use_port ? ':' + config.port : '') + relative_path + '/api/', - relative_path: relative_path + relative_path: relative_path, + minimumTitleLength: 3, + minimumPostLength: 8 }; server_conf.base_url = protocol + '//' + host; server_conf.relative_path = relative_path; server_conf.imgurClientID = ''; + server_conf.post_delay = 10000; install.save(server_conf, client_conf, callback); }); diff --git a/src/posts.js b/src/posts.js index 932c9e7835..c377c3ed70 100644 --- a/src/posts.js +++ b/src/posts.js @@ -10,12 +10,12 @@ var RDB = require('./redis.js'), async = require('async'), plugins = require('./plugins'), reds = require('reds'), + nconf = require('nconf'), + clientConfig = require('../public/config.json'), postSearch = reds.createSearch('nodebbpostsearch'); (function(Posts) { - Posts.minimumPostLength = 8; - Posts.getPostsByTid = function(tid, start, end, callback) { RDB.lrange('tid:' + tid + ':posts', start, end, function(err, pids) { @@ -182,7 +182,7 @@ var RDB = require('./redis.js'), Posts.emitTooManyPostsAlert = function(socket) { socket.emit('event:alert', { title: 'Too many posts!', - message: 'You can only post every '+ (config.post_delay / 1000) + ' seconds.', + message: 'You can only post every '+ (nconf.get('post_delay') / 1000) + ' seconds.', type: 'error', timeout: 2000 }); @@ -192,15 +192,14 @@ var RDB = require('./redis.js'), if(content) { content = content.trim(); } - - if (!content || content.length < Posts.minimumPostLength) { + + if (!content || content.length < clientConfig.minimumPostLength) { callback(new Error('content-too-short'), null); return; } user.getUserField(uid, 'lastposttime', function(lastposttime) { - - if(Date.now() - lastposttime < config.post_delay) { + if(Date.now() - lastposttime < nconf.get('post_delay')) { callback(new Error('too-many-posts'), null); return; } diff --git a/src/topics.js b/src/topics.js index 199e624531..e6d8cb98d3 100644 --- a/src/topics.js +++ b/src/topics.js @@ -11,6 +11,7 @@ var RDB = require('./redis.js') async = require('async'), feed = require('./feed.js'), favourites = require('./favourites.js'), + clientConfig = require('../public/config.json'), reds = require('reds'), topicSearch = reds.createSearch('nodebbtopicsearch'); @@ -20,7 +21,7 @@ marked.setOptions({ (function(Topics) { - Topics.minimumTitleLength = 3; + Topics.getTopicData = function(tid, callback) { RDB.hgetall('topic:' + tid, function(err, data) { @@ -530,7 +531,7 @@ marked.setOptions({ type: 'error', timeout: 2000, title: 'Title too short', - message: "Please enter a longer title. At least " + Topics.minimumTitleLength + " characters.", + message: "Please enter a longer title. At least " + clientConfig.minimumTitleLength + " characters.", alert_id: 'post_error' }); } @@ -547,17 +548,17 @@ marked.setOptions({ if (uid === 0) { callback(new Error('not-logged-in'), null); return; - } else if(!title || title.length < Topics.minimumTitleLength) { + } else if(!title || title.length < clientConfig.minimumTitleLength) { callback(new Error('title-too-short'), null); return; - } else if (!content || content.length < posts.miminumPostLength) { + } else if (!content || content.length < clientConfig.miminumPostLength) { callback(new Error('content-too-short'), null); return; } user.getUserField(uid, 'lastposttime', function(lastposttime) { - if(Date.now() - lastposttime < config.post_delay) { + if(Date.now() - lastposttime < nconf.get('post_delay')) { callback(new Error('too-many-posts'), null); return; } diff --git a/src/websockets.js b/src/websockets.js index 675736e42d..5e48eec84c 100644 --- a/src/websockets.js +++ b/src/websockets.js @@ -366,7 +366,7 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }), if(err) { if(err.message === 'content-too-short') { posts.emitContentTooShortAlert(socket); - } else if(err.messages === 'too-many-posts') { + } else if(err.message === 'too-many-posts') { posts.emitTooManyPostsAlert(socket); } else if(err.message === 'reply-error') { socket.emit('event:alert', { @@ -462,7 +462,7 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }), if(!data.title || data.title.length < topics.minimumTitleLength) { topics.emitTitleTooShortAlert(socket); return; - } else if (!data.content || data.content.length < posts.minimumPostLength) { + } else if (!data.content || data.content.length < require('../public/config.json').minimumPostLength) { posts.emitContentTooShortAlert(socket); return; }