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) { function(next) {
// Applying default database configs // Applying default database configs
var meta = require('./meta'); winston.info('Populating database with default configs, if not already set...')
var meta = require('./meta'),
meta.configs.set('postDelay', 10000); defaults = [
meta.configs.set('minimumPostLength', 8); { field: 'postDelay', value: 10000 },
meta.configs.set('minimumTitleLength', 3); { field: 'minimumPostLength', value: 8 },
meta.configs.set('minimumUsernameLength', 2); { field: 'minimumTitleLength', value: 3 },
meta.configs.set('maximumUsernameLength', 16); { field: 'minimumUsernameLength', value: 2 },
meta.configs.set('minimumPasswordLength', 6); { field: 'maximumUsernameLength', value: 16 },
meta.configs.set('imgurClientID', ''); { field: 'minimumPasswordLength', value: 6 },
{ field: 'imgurClientID', value: '' }
];
async.each(defaults, function(configObj, next) {
meta.configs.setOnEmpty(configObj.field, configObj.value, next);
}, function(err) {
meta.configs.init(next); meta.configs.init(next);
});
}, },
function(next) { function(next) {
// Check if an administrator needs to be created // Check if an administrator needs to be created

@ -2,30 +2,34 @@ var utils = require('./../public/src/utils.js'),
RDB = require('./redis.js'), RDB = require('./redis.js'),
async = require('async'), async = require('async'),
path = require('path'), path = require('path'),
fs = require('fs'); fs = require('fs'),
winston = require('winston');
(function(Meta) { (function(Meta) {
Meta.configs = { Meta.configs = {
init: function(callback) { init: function(callback) {
Meta.configs.get(function(config) { Meta.configs.list(function(err, config) {
if (!err) {
Meta.config = config; Meta.config = config;
callback(); callback();
} else winston.error(err);
}); });
}, },
get: function(callback) { list: function(callback) {
RDB.hgetall('config', function(err, config) { RDB.hgetall('config', function(err, config) {
if (!err) { if (!err) {
config = config || {}; config = config || {};
config.status = 'ok'; config.status = 'ok';
callback(config); callback(err, config);
} else { } else {
callback({ callback(new Error('could-not-read-config'));
status: 'error'
});
} }
}); });
}, },
get: function(field, callback) {
RDB.hget('config', field, callback);
},
getFields: function(fields, callback) { getFields: function(fields, callback) {
RDB.hmgetObject('config', fields, callback); RDB.hmgetObject('config', fields, callback);
}, },
@ -35,6 +39,12 @@ var utils = require('./../public/src/utils.js'),
callback(err, res); 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) { remove: function(field) {
RDB.hdel('config', field); RDB.hdel('config', field);
} }

@ -569,8 +569,8 @@ var SocketIO = require('socket.io').listen(global.server, {
}); });
socket.on('api:config.get', function(data) { socket.on('api:config.get', function(data) {
meta.configs.get(function(config) { meta.configs.list(function(err, config) {
socket.emit('api:config.get', config); if (!err) socket.emit('api:config.get', config);
}); });
}); });

Loading…
Cancel
Save