move dashboard setting into dashboard.js
This commit is contained in:
@@ -1,13 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
exports = module.exports = {
|
||||
initCache,
|
||||
|
||||
// these values come from the cache
|
||||
dashboardDomain,
|
||||
setDashboardLocation,
|
||||
dashboardFqdn,
|
||||
|
||||
get,
|
||||
set,
|
||||
|
||||
@@ -57,22 +50,11 @@ exports = module.exports = {
|
||||
|
||||
const assert = require('assert'),
|
||||
database = require('./database.js'),
|
||||
debug = require('debug')('box:settings'),
|
||||
safe = require('safetydance');
|
||||
|
||||
const SETTINGS_FIELDS = [ 'name', 'value' ].join(',');
|
||||
const SETTINGS_BLOB_FIELDS = [ 'name', 'valueBlob' ].join(',');
|
||||
|
||||
const gDefaults = (function () {
|
||||
const result = { };
|
||||
result[exports.DASHBOARD_DOMAIN_KEY] = '';
|
||||
result[exports.DASHBOARD_FQDN_KEY] = '';
|
||||
|
||||
return result;
|
||||
})();
|
||||
|
||||
let gCache = {};
|
||||
|
||||
async function get(key) {
|
||||
assert.strictEqual(typeof key, 'string');
|
||||
|
||||
@@ -121,41 +103,3 @@ async function setBlob(key, value) {
|
||||
async function clear() {
|
||||
await database.query('DELETE FROM settings');
|
||||
}
|
||||
|
||||
async function list() {
|
||||
const settings = await database.query(`SELECT ${SETTINGS_FIELDS} FROM settings WHERE value IS NOT NULL ORDER BY name`);
|
||||
|
||||
const result = Object.assign({}, gDefaults);
|
||||
settings.forEach(function (setting) { result[setting.name] = setting.value; });
|
||||
|
||||
// convert booleans
|
||||
result[exports.DEMO_KEY] = !!result[exports.DEMO_KEY];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
async function initCache() {
|
||||
debug('initCache: pre-load settings');
|
||||
|
||||
const allSettings = await list();
|
||||
|
||||
gCache = {
|
||||
dashboardDomain: allSettings[exports.DASHBOARD_DOMAIN_KEY],
|
||||
dashboardFqdn: allSettings[exports.DASHBOARD_FQDN_KEY],
|
||||
};
|
||||
}
|
||||
|
||||
// this is together so we can do this in a transaction later
|
||||
async function setDashboardLocation(dashboardDomain, dashboardFqdn) {
|
||||
assert.strictEqual(typeof dashboardDomain, 'string');
|
||||
assert.strictEqual(typeof dashboardFqdn, 'string');
|
||||
|
||||
await set(exports.DASHBOARD_DOMAIN_KEY, dashboardDomain);
|
||||
await set(exports.DASHBOARD_FQDN_KEY, dashboardFqdn);
|
||||
|
||||
gCache.dashboardDomain = dashboardDomain;
|
||||
gCache.dashboardFqdn = dashboardFqdn;
|
||||
}
|
||||
|
||||
function dashboardDomain() { return gCache.dashboardDomain; }
|
||||
function dashboardFqdn() { return gCache.dashboardFqdn; }
|
||||
|
||||
Reference in New Issue
Block a user