diff --git a/core/boot.js b/core/boot.js index fb1697f555..696ea91cc2 100644 --- a/core/boot.js +++ b/core/boot.js @@ -156,6 +156,7 @@ async function initServices({config}) { const {mega} = require('./server/services/mega'); const webhooks = require('./server/services/webhooks'); const appService = require('./frontend/services/apps'); + const limits = require('./server/services/limits'); const scheduling = require('./server/adapters/scheduling'); const urlUtils = require('./shared/url-utils'); @@ -167,6 +168,7 @@ async function initServices({config}) { mega.listen(), webhooks.listen(), appService.init(), + limits.init(), scheduling.init({ // NOTE: When changing API version need to consider how to migrate custom scheduling adapters // that rely on URL to lookup persisted scheduled records (jobs, etc.). Ref: https://github.com/TryGhost/Ghost/pull/10726#issuecomment-489557162 diff --git a/core/server/services/limits.js b/core/server/services/limits.js new file mode 100644 index 0000000000..e93f9b6ac9 --- /dev/null +++ b/core/server/services/limits.js @@ -0,0 +1,24 @@ +const config = require('../../shared/config'); +const db = require('../data/db'); +const LimitService = require('@tryghost/limit-service'); +let limitService = new LimitService(); + +const initFn = () => { + let helpLink; + + if (!config.get('host_settings') || !config.get('host_settings:limits')) { + return; + } + + if (config.get('host_settings:billing:enabled') && config.get('host_settings:billing:enabled') === true && config.get('host_settings:billing:url')) { + helpLink = config.get('host_settings:billing:url'); + } else { + helpLink = 'https://ghost.org/help/'; + } + + limitService.loadLimits({limits: config.get('host_settings:limits'), db, helpLink}); +}; + +module.exports = limitService; + +module.exports.init = initFn; diff --git a/package.json b/package.json index bb266266f8..03177b36ca 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ "@tryghost/kg-default-cards": "4.0.0-rc.6", "@tryghost/kg-markdown-html-renderer": "4.0.0-rc.2", "@tryghost/kg-mobiledoc-html-renderer": "4.0.0-rc.1", + "@tryghost/limit-service": "^0.1.0", "@tryghost/magic-link": "0.6.7", "@tryghost/members-api": "1.0.0-rc.4", "@tryghost/members-csv": "0.4.5", diff --git a/yarn.lock b/yarn.lock index 7652658df9..49b3ef6db8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -495,6 +495,13 @@ dependencies: "@tryghost/kg-clean-basic-html" "^1.0.11" +"@tryghost/limit-service@^0.1.0": + version "0.1.0" + resolved "https://registry.yarnpkg.com/@tryghost/limit-service/-/limit-service-0.1.0.tgz#df0b7c4a04858cf655640e1750ad6923da132de2" + integrity sha512-9BRAqjSNlqZAedSbry2lULvaCaY4ahAbv+7daRfCLu1ieZPBfQ1wc0pqfgdvGnK2pQRb6X/1WNRHkuaCQigPtg== + dependencies: + lodash "^4.17.21" + "@tryghost/magic-link@0.6.7", "@tryghost/magic-link@^0.6.7": version "0.6.7" resolved "https://registry.yarnpkg.com/@tryghost/magic-link/-/magic-link-0.6.7.tgz#9bdf76fa014f08a09cc38c308d659900626902c9" @@ -5991,7 +5998,7 @@ lodash@4.17.20, lodash@^4.17.20, lodash@~4.17.20: resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.20.tgz#b44a9b6297bcb698f1c51a3545a2b3b368d59c52" integrity sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA== -lodash@4.17.21: +lodash@4.17.21, lodash@^4.17.21: version "4.17.21" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==