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