mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 20:16:04 +01:00
closed #275, refactored configs to use new method "list", which returns error first
This commit is contained in:
@@ -95,17 +95,23 @@ var async = require('async'),
|
||||
},
|
||||
function(next) {
|
||||
// Applying default database configs
|
||||
var meta = require('./meta');
|
||||
winston.info('Populating database with default configs, if not already set...')
|
||||
var meta = require('./meta'),
|
||||
defaults = [
|
||||
{ field: 'postDelay', value: 10000 },
|
||||
{ field: 'minimumPostLength', value: 8 },
|
||||
{ field: 'minimumTitleLength', value: 3 },
|
||||
{ field: 'minimumUsernameLength', value: 2 },
|
||||
{ field: 'maximumUsernameLength', value: 16 },
|
||||
{ field: 'minimumPasswordLength', value: 6 },
|
||||
{ field: 'imgurClientID', value: '' }
|
||||
];
|
||||
|
||||
meta.configs.set('postDelay', 10000);
|
||||
meta.configs.set('minimumPostLength', 8);
|
||||
meta.configs.set('minimumTitleLength', 3);
|
||||
meta.configs.set('minimumUsernameLength', 2);
|
||||
meta.configs.set('maximumUsernameLength', 16);
|
||||
meta.configs.set('minimumPasswordLength', 6);
|
||||
meta.configs.set('imgurClientID', '');
|
||||
|
||||
meta.configs.init(next);
|
||||
async.each(defaults, function(configObj, next) {
|
||||
meta.configs.setOnEmpty(configObj.field, configObj.value, next);
|
||||
}, function(err) {
|
||||
meta.configs.init(next);
|
||||
});
|
||||
},
|
||||
function(next) {
|
||||
// Check if an administrator needs to be created
|
||||
|
||||
28
src/meta.js
28
src/meta.js
@@ -2,30 +2,34 @@ var utils = require('./../public/src/utils.js'),
|
||||
RDB = require('./redis.js'),
|
||||
async = require('async'),
|
||||
path = require('path'),
|
||||
fs = require('fs');
|
||||
fs = require('fs'),
|
||||
winston = require('winston');
|
||||
|
||||
(function(Meta) {
|
||||
|
||||
Meta.configs = {
|
||||
init: function(callback) {
|
||||
Meta.configs.get(function(config) {
|
||||
Meta.config = config;
|
||||
callback();
|
||||
Meta.configs.list(function(err, config) {
|
||||
if (!err) {
|
||||
Meta.config = config;
|
||||
callback();
|
||||
} else winston.error(err);
|
||||
});
|
||||
},
|
||||
get: function(callback) {
|
||||
list: function(callback) {
|
||||
RDB.hgetall('config', function(err, config) {
|
||||
if (!err) {
|
||||
config = config || {};
|
||||
config.status = 'ok';
|
||||
callback(config);
|
||||
callback(err, config);
|
||||
} else {
|
||||
callback({
|
||||
status: 'error'
|
||||
});
|
||||
callback(new Error('could-not-read-config'));
|
||||
}
|
||||
});
|
||||
},
|
||||
get: function(field, callback) {
|
||||
RDB.hget('config', field, callback);
|
||||
},
|
||||
getFields: function(fields, callback) {
|
||||
RDB.hmgetObject('config', fields, callback);
|
||||
},
|
||||
@@ -35,6 +39,12 @@ var utils = require('./../public/src/utils.js'),
|
||||
callback(err, res);
|
||||
});
|
||||
},
|
||||
setOnEmpty: function(field, value, callback) {
|
||||
this.get(field, function(err, curValue) {
|
||||
if (!curValue) Meta.configs.set(field, value, callback);
|
||||
else callback();
|
||||
});
|
||||
},
|
||||
remove: function(field) {
|
||||
RDB.hdel('config', field);
|
||||
}
|
||||
|
||||
@@ -569,8 +569,8 @@ var SocketIO = require('socket.io').listen(global.server, {
|
||||
});
|
||||
|
||||
socket.on('api:config.get', function(data) {
|
||||
meta.configs.get(function(config) {
|
||||
socket.emit('api:config.get', config);
|
||||
meta.configs.list(function(err, config) {
|
||||
if (!err) socket.emit('api:config.get', config);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user