mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
refs: https://github.com/TryGhost/Toolbox/issues/229 - we are getting rid of the concept of having multiple api versions in a single ghost install - removed all the code for multiple api versions & left canary wired up, but without the version in the URL - TODO: reorganise the folders so there's no canary folder when we're closer to shipping we need to minimise the pain of merging changes across from main for now
54 lines
1.5 KiB
JavaScript
54 lines
1.5 KiB
JavaScript
const Promise = require('bluebird');
|
|
const events = require('../../../lib/common/events');
|
|
const localUtils = require('../utils');
|
|
const PostScheduler = require('./post-scheduler');
|
|
const getSchedulerIntegration = require('./scheduler-intergation');
|
|
|
|
/**
|
|
* @description Load all scheduled posts/pages from database.
|
|
* @return {Promise}
|
|
*/
|
|
const loadScheduledResources = async function () {
|
|
const api = require('../../../api').endpoints;
|
|
const SCHEDULED_RESOURCES = ['post', 'page'];
|
|
|
|
// Fetches all scheduled resources(posts/pages) with default API
|
|
const results = await Promise.mapSeries(SCHEDULED_RESOURCES, async (resourceType) => {
|
|
const result = await api.schedules.getScheduled.query({
|
|
options: {
|
|
resource: resourceType
|
|
}
|
|
});
|
|
|
|
return result[resourceType] || [];
|
|
});
|
|
|
|
return SCHEDULED_RESOURCES.reduce(function (obj, entry, index) {
|
|
return Object.assign(obj, {
|
|
[entry]: results[index]
|
|
});
|
|
}, {});
|
|
};
|
|
|
|
const init = async (options) => {
|
|
const integration = await getSchedulerIntegration();
|
|
const adapter = await localUtils.createAdapter();
|
|
|
|
let scheduledResources;
|
|
|
|
if (!adapter.rescheduleOnBoot) {
|
|
scheduledResources = [];
|
|
} else {
|
|
scheduledResources = await loadScheduledResources();
|
|
}
|
|
|
|
return new PostScheduler({
|
|
apiUrl: options.apiUrl,
|
|
integration,
|
|
adapter,
|
|
scheduledResources,
|
|
events
|
|
});
|
|
};
|
|
|
|
module.exports = init;
|