0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00

Simplified route settings module api

refs https://linear.app/tryghost/issue/CORE-35/refactor-route-and-redirect-settings

- Made clear distinction around the methods that are exposed for the API use and for the internal use. Same pattern can be found in themese's and redirects module APIs
This commit is contained in:
Naz 2021-09-28 09:47:42 +02:00
parent 328a88087b
commit 1c8c55992a
2 changed files with 26 additions and 16 deletions

View file

@ -1 +1,23 @@
module.exports = require('./route-settings');
const routeSettings = require('./route-settings');
const SettingsLoader = require('./loader');
const ensureSettingsFile = require('./ensure-settings');
module.exports = {
init: async () => {
// Make sure that supported settings files are available
// inside of the `content/setting` directory
return ensureSettingsFile('routes.yaml');
},
loadRouteSettingsSync: SettingsLoader.loadSettingsSync,
loadRouteSettings: SettingsLoader.loadSettings,
getDefaultHash: routeSettings.getDefaultHash,
/**
* Methods used in the API
*/
api: {
setFromFilePath: routeSettings.setFromFilePath,
get: routeSettings.get,
getCurrentHash: routeSettings.getCurrentHash
}
};

View file

@ -10,7 +10,6 @@ const errors = require('@tryghost/errors');
const tpl = require('@tryghost/tpl');
const config = require('../../../shared/config');
const bridge = require('../../../bridge');
const ensureSettingsFile = require('./ensure-settings');
const SettingsLoader = require('./loader');
const messages = {
@ -133,18 +132,6 @@ const get = async () => {
return readFile(settingsFilePath);
};
const init = function () {
debug('init routes settings service');
// Make sure that supported settings files are available
// inside of the `content/setting` directory
return ensureSettingsFile('routes.yaml');
};
module.exports.init = init;
module.exports.loadRouteSettingsSync = SettingsLoader.loadSettingsSync;
module.exports.loadRouteSettings = SettingsLoader.loadSettings;
/**
* md5 hashes of default routes settings
*/
@ -156,7 +143,7 @@ const calculateHash = (data) => {
.digest('hex');
};
module.exports.getDefaultHash = () => {
const getDefaultHash = () => {
return defaultRoutesSettingHash;
};
@ -166,7 +153,8 @@ const getCurrentHash = async () => {
return calculateHash(JSON.stringify(data));
};
module.exports.api = {
module.exports = {
getDefaultHash: getDefaultHash,
setFromFilePath: setFromFilePath,
get: get,
getCurrentHash: getCurrentHash