You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nodebb/src/meta/configs.js

73 lines
1.4 KiB
JavaScript

11 years ago
'use strict';
var winston = require('winston'),
db = require('../database');
module.exports = function(Meta) {
Meta.config = {};
Meta.configs = {};
Meta.configs.init = function (callback) {
delete Meta.config;
Meta.configs.list(function (err, config) {
if (err) {
10 years ago
winston.error(err.stack);
11 years ago
return callback(err);
}
Meta.config = config;
callback();
});
};
Meta.configs.list = function (callback) {
db.getObject('config', function (err, config) {
callback(err, config || {});
});
};
Meta.configs.get = function (field, callback) {
db.getObjectField('config', field, callback);
};
Meta.configs.getFields = function (fields, callback) {
db.getObjectFields('config', fields, callback);
};
Meta.configs.set = function (field, value, callback) {
callback = callback || function() {};
if (!field) {
return callback(new Error('invalid config field'));
}
db.setObjectField('config', field, value, function(err, res) {
if (!err && Meta.config) {
Meta.config[field] = value;
}
callback(err, res);
});
};
Meta.configs.setOnEmpty = function (field, value, callback) {
Meta.configs.get(field, function (err, curValue) {
if (err) {
return callback(err);
}
if (!curValue) {
Meta.configs.set(field, value, callback);
} else {
callback();
}
});
};
Meta.configs.remove = function (field) {
db.deleteObjectField('config', field);
};
};