mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 01:41:46 +03:00
5e5b90ac29
refs #9192 - Introduces a url service that can be initialised - Added a concept of Resources and resource config.json that contains details about the resources in the system that we may want to make customisable - Note that individual resources know how to create their own Urls... this is important for later - Url Service loads all of the resources, and stores their URLs - The UrlService binds to all events, so that when a resource changes its url and related data can be updated if needed - There is a temporary config guard so that this can be turned off easily
40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
'use strict';
|
|
// Based heavily on the settings cache
|
|
const _ = require('lodash'),
|
|
debug = require('ghost-ignition').debug('services:url:cache'),
|
|
events = require('../../events'),
|
|
urlCache = {};
|
|
|
|
module.exports = {
|
|
/**
|
|
* Get the entire cache object
|
|
* Uses clone to prevent modifications from being reflected
|
|
* @return {{}} urlCache
|
|
*/
|
|
getAll() {
|
|
return _.cloneDeep(urlCache);
|
|
},
|
|
set(key, value) {
|
|
const existing = this.get(key);
|
|
|
|
if (!existing) {
|
|
debug('adding url', key);
|
|
urlCache[key] = _.cloneDeep(value);
|
|
events.emit('url.added', key, value);
|
|
} else if (!_.isEqual(value, existing)) {
|
|
debug('overwriting url', key);
|
|
urlCache[key] = _.cloneDeep(value);
|
|
events.emit('url.edited', key, value);
|
|
}
|
|
},
|
|
unset(key) {
|
|
const value = this.get(key);
|
|
delete urlCache[key];
|
|
debug('removing url', key);
|
|
events.emit('url.removed', key, value);
|
|
},
|
|
get(key) {
|
|
return _.cloneDeep(urlCache[key]);
|
|
}
|
|
};
|