Bootstrapped media inlining trigger endpoint

refs https://github.com/TryGhost/Toolbox/issues/524

- Added an endpoint to Admin API under `POST /db/media/inline` that accepts `domains` as JSON payload triggering media inlining job
This commit is contained in:
Naz 2023-03-03 14:26:52 +08:00
parent da78e235dd
commit de87479fb9
No known key found for this signature in database
4 changed files with 26 additions and 2 deletions

View File

@ -3,6 +3,7 @@ const moment = require('moment-timezone');
const dbBackup = require('../../data/db/backup'); const dbBackup = require('../../data/db/backup');
const exporter = require('../../data/exporter'); const exporter = require('../../data/exporter');
const importer = require('../../data/importer'); const importer = require('../../data/importer');
const mediaInliner = require('../../services/media-inliner');
const errors = require('@tryghost/errors'); const errors = require('@tryghost/errors');
const models = require('../../models'); const models = require('../../models');
const settingsCache = require('../../../shared/settings-cache'); const settingsCache = require('../../../shared/settings-cache');
@ -93,6 +94,22 @@ module.exports = {
} }
}, },
inlineMedia: {
permissions: {
method: 'importContent'
},
validation: {
options: {
include: {
values: ['domains']
}
}
},
async query(frame) {
return mediaInliner.api.startMediaInliner(frame.data.domains);
}
},
deleteAllContent: { deleteAllContent: {
headers: { headers: {
cacheInvalidate: true cacheInvalidate: true

View File

@ -0,0 +1 @@
module.exports = require('./service');

View File

@ -5,8 +5,8 @@ module.exports = {
this.api = { this.api = {
// @NOTE: the inlining should become an offloaded job // @NOTE: the inlining should become an offloaded job
// startMediaInliner: mediaInliner.inlineMedia // startMediaInliner: mediaInliner.inlineMedia
startMediaInliner: () => { startMediaInliner: (domains) => {
debug('[Inliner] Starting media inlining job'); debug('[Inliner] Starting media inlining job for domains: ', domains);
return { return {
status: 'success' status: 'success'
}; };

View File

@ -205,6 +205,12 @@ module.exports = function apiRoutes() {
http(api.db.backupContent) http(api.db.backupContent)
); );
router.post('/db/media/inline',
mw.authAdminApi,
labs.enabledMiddleware('mediaInliner'),
http(api.db.inlineMedia)
);
// ## Slack // ## Slack
router.post('/slack/test', mw.authAdminApi, http(api.slack.sendTest)); router.post('/slack/test', mw.authAdminApi, http(api.slack.sendTest));