mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 10:21:36 +03:00
93af11bdec
refs https://linear.app/tryghost/issue/CORE-35/refactor-route-and-redirect-settings - 'knowSettings' was based on a "configurable" array of settings that might be configured in Ghost. The multitude never happened! The only setting the frontend takes care of is routes.yaml file (redirects is also kind of a setting but is a separate concept for now). - Having just one type of file to deal with allows to simplify implementation significantly, which helps before a big refactor
49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
const crypto = require('crypto');
|
|
const debug = require('@tryghost/debug')('frontend:services:settings:index');
|
|
const SettingsLoader = require('./loader');
|
|
const ensureSettingsFile = require('./ensure-settings');
|
|
|
|
/**
|
|
* md5 hashes of default settings
|
|
*/
|
|
const defaultHashes = {
|
|
routes: '3d180d52c663d173a6be791ef411ed01'
|
|
};
|
|
|
|
const calculateHash = (data) => {
|
|
return crypto.createHash('md5')
|
|
.update(data, 'binary')
|
|
.digest('hex');
|
|
};
|
|
|
|
module.exports = {
|
|
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');
|
|
},
|
|
|
|
/**
|
|
* Getter for routes YAML setting.
|
|
* Example: `settings.get().then(...)`
|
|
* will return a JSON Object like this:
|
|
* {routes: {}, collections: {}, resources: {}}
|
|
* @returns {Object} routes.yaml in JSON format
|
|
*/
|
|
get: function get() {
|
|
return SettingsLoader('routes');
|
|
},
|
|
|
|
getDefaulHash: (setting) => {
|
|
return defaultHashes[setting];
|
|
},
|
|
|
|
getCurrentHash: async (setting) => {
|
|
const data = await SettingsLoader.loadSettings(setting);
|
|
|
|
return calculateHash(JSON.stringify(data));
|
|
}
|
|
};
|