add api to get/set footer and remove all use of custom.js
This commit is contained in:
+1
-3
@@ -33,11 +33,9 @@ var apps = require('./apps.js'),
|
||||
debug = require('debug')('box:cloudron'),
|
||||
domains = require('./domains.js'),
|
||||
eventlog = require('./eventlog.js'),
|
||||
custom = require('./custom.js'),
|
||||
fs = require('fs'),
|
||||
mail = require('./mail.js'),
|
||||
notifications = require('./notifications.js'),
|
||||
os = require('os'),
|
||||
path = require('path'),
|
||||
paths = require('./paths.js'),
|
||||
platform = require('./platform.js'),
|
||||
@@ -136,7 +134,7 @@ function getConfig(callback) {
|
||||
isDemo: settings.isDemo(),
|
||||
provider: settings.provider(),
|
||||
cloudronName: allSettings[settings.CLOUDRON_NAME_KEY],
|
||||
uiSpec: custom.uiSpec()
|
||||
footer: allSettings[settings.FOOTER_KEY]
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
let debug = require('debug')('box:custom'),
|
||||
lodash = require('lodash'),
|
||||
paths = require('./paths.js'),
|
||||
safe = require('safetydance'),
|
||||
yaml = require('js-yaml');
|
||||
|
||||
exports = module.exports = {
|
||||
uiSpec: uiSpec,
|
||||
spec: spec
|
||||
};
|
||||
|
||||
const DEFAULT_SPEC = {
|
||||
footer: {
|
||||
body: '© 2020 [Cloudron](https://cloudron.io) [Forum <i class="fa fa-comments"></i>](https://forum.cloudron.io)'
|
||||
}
|
||||
};
|
||||
|
||||
const gSpec = (function () {
|
||||
try {
|
||||
if (!safe.fs.existsSync(paths.CUSTOM_FILE)) return DEFAULT_SPEC;
|
||||
const c = yaml.safeLoad(safe.fs.readFileSync(paths.CUSTOM_FILE, 'utf8'));
|
||||
return lodash.merge({}, DEFAULT_SPEC, c);
|
||||
} catch (e) {
|
||||
debug(`Error loading features file from ${paths.CUSTOM_FILE} : ${e.message}`);
|
||||
return DEFAULT_SPEC;
|
||||
}
|
||||
})();
|
||||
|
||||
// flags sent to the UI. this is separate because we have values that are secret to the backend
|
||||
function uiSpec() {
|
||||
return gSpec;
|
||||
}
|
||||
|
||||
function spec() {
|
||||
return gSpec;
|
||||
}
|
||||
@@ -23,8 +23,6 @@ exports = module.exports = {
|
||||
APPS_DATA_DIR: path.join(baseDir(), 'appsdata'),
|
||||
BOX_DATA_DIR: path.join(baseDir(), 'boxdata'),
|
||||
|
||||
CUSTOM_FILE: path.join(baseDir(), 'boxdata/custom.yml'),
|
||||
|
||||
ACME_CHALLENGES_DIR: path.join(baseDir(), 'platformdata/acme'),
|
||||
ADDON_CONFIG_DIR: path.join(baseDir(), 'platformdata/addons'),
|
||||
COLLECTD_APPCONFIG_DIR: path.join(baseDir(), 'platformdata/collectd/collectd.conf.d'),
|
||||
|
||||
@@ -97,6 +97,26 @@ function setTimeZone(req, res, next) {
|
||||
});
|
||||
}
|
||||
|
||||
function getFooter(req, res, next) {
|
||||
settings.getFooter(function (error, footer) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, { footer }));
|
||||
});
|
||||
}
|
||||
|
||||
function setFooter(req, res, next) {
|
||||
assert.strictEqual(typeof req.body, 'object');
|
||||
|
||||
if (typeof req.body.footer !== 'string') return next(new HttpError(400, 'footer is required'));
|
||||
|
||||
settings.setFooter(req.body.footer, function (error) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, {}));
|
||||
});
|
||||
}
|
||||
|
||||
function setCloudronAvatar(req, res, next) {
|
||||
assert.strictEqual(typeof req.files, 'object');
|
||||
|
||||
@@ -306,6 +326,8 @@ function get(req, res, next) {
|
||||
case settings.TIME_ZONE_KEY: return getTimeZone(req, res, next);
|
||||
case settings.CLOUDRON_NAME_KEY: return getCloudronName(req, res, next);
|
||||
|
||||
case settings.FOOTER_KEY: return getFooter(req, res, next);
|
||||
|
||||
case settings.CLOUDRON_AVATAR_KEY: return getCloudronAvatar(req, res, next);
|
||||
|
||||
default: return next(new HttpError(404, 'No such setting'));
|
||||
@@ -329,6 +351,8 @@ function set(req, res, next) {
|
||||
case settings.TIME_ZONE_KEY: return setTimeZone(req, res, next);
|
||||
case settings.CLOUDRON_NAME_KEY: return setCloudronName(req, res, next);
|
||||
|
||||
case settings.FOOTER_KEY: return setFooter(req, res, next);
|
||||
|
||||
case settings.CLOUDRON_AVATAR_KEY: return setCloudronAvatar(req, res, next);
|
||||
|
||||
default: return next(new HttpError(404, 'No such setting'));
|
||||
|
||||
@@ -46,6 +46,9 @@ exports = module.exports = {
|
||||
getSysinfoConfig: getSysinfoConfig,
|
||||
setSysinfoConfig: setSysinfoConfig,
|
||||
|
||||
getFooter: getFooter,
|
||||
setFooter: setFooter,
|
||||
|
||||
provider: provider,
|
||||
|
||||
getAll: getAll,
|
||||
@@ -91,6 +94,8 @@ exports = module.exports = {
|
||||
ADMIN_FQDN_KEY: 'admin_fqdn',
|
||||
PROVIDER_KEY: 'provider',
|
||||
|
||||
FOOTER_KEY: 'footer',
|
||||
|
||||
// blobs
|
||||
CLOUDRON_AVATAR_KEY: 'cloudron_avatar', // not stored in db but can be used for locked flag
|
||||
|
||||
@@ -150,6 +155,8 @@ let gDefaults = (function () {
|
||||
result[exports.WEB_SERVER_ORIGIN_KEY] = 'https://cloudron.io';
|
||||
result[exports.DEMO_KEY] = false;
|
||||
|
||||
result[exports.FOOTER_KEY] = '© 2020 [Cloudron](https://cloudron.io) [Forum <i class="fa fa-comments"></i>](https://forum.cloudron.io)';
|
||||
|
||||
return result;
|
||||
})();
|
||||
|
||||
@@ -661,6 +668,30 @@ function setApiServerOrigin(origin, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function getFooter(callback) {
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
settingsdb.get(exports.FOOTER_KEY, function (error, value) {
|
||||
if (error && error.reason === BoxError.NOT_FOUND) return callback(null, gDefaults[exports.FOOTER_KEY]);
|
||||
if (error) return callback(error);
|
||||
|
||||
callback(null, value);
|
||||
});
|
||||
}
|
||||
|
||||
function setFooter(footer, callback) {
|
||||
assert.strictEqual(typeof footer, 'string');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
settingsdb.set(exports.FOOTER_KEY, footer, function (error) {
|
||||
if (error) return callback(error);
|
||||
|
||||
notifyChange(exports.FOOTER_KEY, footer);
|
||||
|
||||
callback(null);
|
||||
});
|
||||
}
|
||||
|
||||
function provider() { return gCache.provider; }
|
||||
function apiServerOrigin() { return gCache.apiServerOrigin; }
|
||||
function webServerOrigin() { return gCache.webServerOrigin; }
|
||||
|
||||
Reference in New Issue
Block a user