closed #275, refactored configs to use new method "list", which returns error first

v1.18.x
Julian Lam 12 years ago
parent ae6f9fc87c
commit cffbc76da1

@ -95,17 +95,23 @@ var async = require('async'),
},
function(next) {
// Applying default database configs
var meta = require('./meta');
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', '');
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.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

@ -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);
});
});

Loading…
Cancel
Save