mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 11:34:24 +03:00
1421c92ba5
refs #6413 - PUT endpoint to publish a post/page for the scheduler - fn endpoint to get all scheduled posts (with from/to query params) for the scheduler - hardcoded permission handling for scheduler client - fix event bug: unscheduled - basic structure for scheduling - post scheduling basics - offer easy option to change adapter - integrate the default scheduler adapter - update scheduled posts when blog TZ changes - safety check before scheduler can publish a post (not allowed to publish in the future or past) - add force flag to allow publishing in the past - invalidate cache header for /schedules/posts/:id
55 lines
1.8 KiB
JavaScript
55 lines
1.8 KiB
JavaScript
var _ = require('lodash'),
|
|
Promise = require('bluebird'),
|
|
SchedulingBase = require(__dirname + '/SchedulingBase'),
|
|
errors = require(__dirname + '/../errors');
|
|
|
|
exports.createAdapter = function (options) {
|
|
options = options || {};
|
|
|
|
var adapter = null,
|
|
activeAdapter = options.active,
|
|
path = options.path;
|
|
|
|
if (!activeAdapter) {
|
|
return Promise.reject(new errors.IncorrectUsage('Please provide an active adapter.'));
|
|
}
|
|
|
|
/**
|
|
* CASE: active adapter is a npm module
|
|
*/
|
|
try {
|
|
adapter = new (require(activeAdapter))(options);
|
|
} catch (err) {
|
|
if (err.code !== 'MODULE_NOT_FOUND') {
|
|
return Promise.reject(new errors.IncorrectUsage(err.message));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* CASE: active adapter is located in specific ghost path
|
|
*/
|
|
try {
|
|
adapter = adapter || new (require(path + activeAdapter))(options);
|
|
} catch (err) {
|
|
if (err.code === 'MODULE_NOT_FOUND') {
|
|
return Promise.reject(new errors.IncorrectUsage('MODULE_NOT_FOUND', activeAdapter));
|
|
}
|
|
|
|
return Promise.reject(new errors.IncorrectUsage(err.message));
|
|
}
|
|
|
|
if (!(adapter instanceof SchedulingBase)) {
|
|
return Promise.reject(new errors.IncorrectUsage('Your adapter does not inherit from the SchedulingBase.'));
|
|
}
|
|
|
|
if (!adapter.requiredFns) {
|
|
return Promise.reject(new errors.IncorrectUsage('Your adapter does not provide the minimum required functions.'));
|
|
}
|
|
|
|
if (_.xor(adapter.requiredFns, Object.keys(_.pick(Object.getPrototypeOf(adapter), adapter.requiredFns))).length) {
|
|
return Promise.reject(new errors.IncorrectUsage('Your adapter does not provide the minimum required functions.'));
|
|
}
|
|
|
|
return Promise.resolve(adapter);
|
|
};
|