mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 10:21:36 +03:00
4a47e8d0a8
refs https://linear.app/tryghost/issue/CORE-35/refactor-route-and-redirect-settings - It was not clear from the module signature/usages that the default method is executing synchronously. The change makes it explicit. Knowing if the method is synchronous is helpful to stop possible pefr bottlenecks!
47 lines
1.3 KiB
JavaScript
47 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 routes settings
|
|
*/
|
|
const defaultRoutesSettingHash = '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.loadSettingsSync('routes');
|
|
},
|
|
|
|
getDefaultHash: () => {
|
|
return defaultRoutesSettingHash;
|
|
},
|
|
|
|
getCurrentHash: async () => {
|
|
const data = await SettingsLoader.loadSettings('routes');
|
|
|
|
return calculateHash(JSON.stringify(data));
|
|
}
|
|
};
|