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 exporter = require('../../data/exporter');
const importer = require('../../data/importer');
const mediaInliner = require('../../services/media-inliner');
const errors = require('@tryghost/errors');
const models = require('../../models');
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: {
headers: {
cacheInvalidate: true

View File

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

View File

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

View File

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