mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-06 22:15:48 +01:00
moved confings into redis
This commit is contained in:
@@ -9,7 +9,7 @@ var socket,
|
||||
function loadConfig() {
|
||||
|
||||
$.ajax({
|
||||
url: RELATIVE_PATH + '/config.json?v=' + new Date().getTime(),
|
||||
url: RELATIVE_PATH + '/api/config',
|
||||
success: function(data) {
|
||||
API_URL = data.api_url;
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ var async = require('async'),
|
||||
fs = require('fs'),
|
||||
url = require('url'),
|
||||
path = require('path'),
|
||||
meta = require('./meta'),
|
||||
install = {
|
||||
questions: [
|
||||
'base_url|Publically accessible URL of this installation? (http://localhost)',
|
||||
@@ -78,15 +79,16 @@ var async = require('async'),
|
||||
port: config.port
|
||||
},
|
||||
api_url: protocol + '//' + host + (config.use_port ? ':' + config.port : '') + relative_path + '/api/',
|
||||
relative_path: relative_path,
|
||||
minimumTitleLength: 3,
|
||||
minimumPostLength: 8
|
||||
relative_path: relative_path
|
||||
};
|
||||
|
||||
server_conf.base_url = protocol + '//' + host;
|
||||
server_conf.relative_path = relative_path;
|
||||
server_conf.imgurClientID = '';
|
||||
server_conf.post_delay = 10000;
|
||||
|
||||
meta.config.set('postDelay', 10000);
|
||||
meta.config.set('minimumPostLength', 8);
|
||||
meta.config.set('minimumTitleLength', 3);
|
||||
|
||||
install.save(server_conf, client_conf, callback);
|
||||
});
|
||||
|
||||
@@ -19,9 +19,13 @@ var utils = require('./../public/src/utils.js'),
|
||||
}
|
||||
});
|
||||
},
|
||||
getFields: function(fields, callback) {
|
||||
RDB.hmgetObject('config', fields, callback);
|
||||
},
|
||||
set: function(field, value, callback) {
|
||||
RDB.hset('config', field, value, function(err, res) {
|
||||
callback(err);
|
||||
if(callback)
|
||||
callback(err, res);
|
||||
});
|
||||
},
|
||||
remove: function(field) {
|
||||
|
||||
@@ -3,7 +3,8 @@ var user = require('./../user.js'),
|
||||
topics = require('./../topics.js'),
|
||||
categories = require('./../categories.js')
|
||||
utils = require('./../../public/src/utils.js'),
|
||||
pkg = require('../../package.json');
|
||||
pkg = require('../../package.json'),
|
||||
meta = require('./../meta.js');
|
||||
|
||||
|
||||
(function(Api) {
|
||||
@@ -14,6 +15,19 @@ var user = require('./../user.js'),
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/api/config', function(req, res, next) {
|
||||
meta.config.getFields(['postDelay', 'minimumTitleLength', 'minimumPostLength'], function(err, metaConfig) {
|
||||
if(err) return next();
|
||||
var clientConfig = require('../../public/config.json');
|
||||
|
||||
for (var attrname in metaConfig) {
|
||||
clientConfig[attrname] = metaConfig[attrname];
|
||||
}
|
||||
|
||||
res.json(200, clientConfig);
|
||||
})
|
||||
});
|
||||
|
||||
app.get('/api/home', function(req, res) {
|
||||
var uid = (req.user) ? req.user.uid : 0;
|
||||
categories.getAllCategories(function(data) {
|
||||
|
||||
@@ -11,7 +11,6 @@ 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');
|
||||
|
||||
@@ -531,7 +530,7 @@ marked.setOptions({
|
||||
type: 'error',
|
||||
timeout: 2000,
|
||||
title: 'Title too short',
|
||||
message: "Please enter a longer title. At least " + clientConfig.minimumTitleLength + " characters.",
|
||||
message: "Please enter a longer title. At least " + config.minimumTitleLength + " characters.",
|
||||
alert_id: 'post_error'
|
||||
});
|
||||
}
|
||||
@@ -548,17 +547,17 @@ marked.setOptions({
|
||||
if (uid === 0) {
|
||||
callback(new Error('not-logged-in'), null);
|
||||
return;
|
||||
} else if(!title || title.length < clientConfig.minimumTitleLength) {
|
||||
} else if(!title || title.length < config.minimumTitleLength) {
|
||||
callback(new Error('title-too-short'), null);
|
||||
return;
|
||||
} else if (!content || content.length < clientConfig.miminumPostLength) {
|
||||
} else if (!content || content.length < config.miminumPostLength) {
|
||||
callback(new Error('content-too-short'), null);
|
||||
return;
|
||||
}
|
||||
|
||||
user.getUserField(uid, 'lastposttime', function(lastposttime) {
|
||||
|
||||
if(Date.now() - lastposttime < nconf.get('post_delay')) {
|
||||
if(Date.now() - lastposttime < config.postDelay) {
|
||||
callback(new Error('too-many-posts'), null);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user