mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-29 13:52:10 +03:00
ES6 migration: server/adapters/scheduling/post-scheduling (#9698)
refs #9589
This commit is contained in:
parent
74a6a413ed
commit
3e07bbd987
@ -1,4 +1,4 @@
|
||||
var postScheduling = require(__dirname + '/post-scheduling');
|
||||
const postScheduling = require(__dirname + '/post-scheduling');
|
||||
|
||||
/**
|
||||
* scheduling modules:
|
||||
|
@ -1,4 +1,4 @@
|
||||
var Promise = require('bluebird'),
|
||||
const Promise = require('bluebird'),
|
||||
moment = require('moment'),
|
||||
localUtils = require('../utils'),
|
||||
common = require('../../../lib/common'),
|
||||
@ -8,13 +8,11 @@ var Promise = require('bluebird'),
|
||||
_private = {};
|
||||
|
||||
_private.normalize = function normalize(options) {
|
||||
var object = options.object,
|
||||
apiUrl = options.apiUrl,
|
||||
client = options.client;
|
||||
const {object, apiUrl, client} = options;
|
||||
|
||||
return {
|
||||
time: moment(object.get('published_at')).valueOf(),
|
||||
url: urlService.utils.urlJoin(apiUrl, 'schedules', 'posts', object.get('id')) + '?client_id=' + client.get('slug') + '&client_secret=' + client.get('secret'),
|
||||
url: `${urlService.utils.urlJoin(apiUrl, 'schedules', 'posts', object.get('id'))}?client_id=${client.get('slug')}&client_secret=${client.get('secret')}`,
|
||||
extra: {
|
||||
httpMethod: 'PUT',
|
||||
oldTime: object.updated('published_at') ? moment(object.updated('published_at')).valueOf() : null
|
||||
@ -28,18 +26,17 @@ _private.loadClient = function loadClient() {
|
||||
|
||||
_private.loadScheduledPosts = function () {
|
||||
return schedules.getScheduledPosts()
|
||||
.then(function (result) {
|
||||
.then((result) => {
|
||||
return result.posts || [];
|
||||
});
|
||||
};
|
||||
|
||||
exports.init = function init(options) {
|
||||
var config = options || {},
|
||||
apiUrl = config.apiUrl,
|
||||
adapter = null,
|
||||
exports.init = function init(options = {}) {
|
||||
const {apiUrl} = options;
|
||||
let adapter = null,
|
||||
client = null;
|
||||
|
||||
if (!config) {
|
||||
if (!Object.keys(options).length) {
|
||||
return Promise.reject(new common.errors.IncorrectUsageError({message: 'post-scheduling: no config was provided'}));
|
||||
}
|
||||
|
||||
@ -48,49 +45,49 @@ exports.init = function init(options) {
|
||||
}
|
||||
|
||||
return _private.loadClient()
|
||||
.then(function (_client) {
|
||||
.then((_client) => {
|
||||
client = _client;
|
||||
return localUtils.createAdapter(config);
|
||||
return localUtils.createAdapter(options);
|
||||
})
|
||||
.then(function (_adapter) {
|
||||
.then((_adapter) => {
|
||||
adapter = _adapter;
|
||||
if (!adapter.rescheduleOnBoot) {
|
||||
return [];
|
||||
}
|
||||
return _private.loadScheduledPosts();
|
||||
})
|
||||
.then(function (scheduledPosts) {
|
||||
.then((scheduledPosts) => {
|
||||
if (!scheduledPosts.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
scheduledPosts.forEach(function (object) {
|
||||
adapter.reschedule(_private.normalize({object: object, apiUrl: apiUrl, client: client}));
|
||||
scheduledPosts.forEach((object) => {
|
||||
adapter.reschedule(_private.normalize({object, apiUrl, client}));
|
||||
});
|
||||
})
|
||||
.then(function () {
|
||||
.then(() => {
|
||||
adapter.run();
|
||||
})
|
||||
.then(function () {
|
||||
.then(() => {
|
||||
common.events.onMany([
|
||||
'post.scheduled',
|
||||
'page.scheduled'
|
||||
], function (object) {
|
||||
adapter.schedule(_private.normalize({object: object, apiUrl: apiUrl, client: client}));
|
||||
], (object) => {
|
||||
adapter.schedule(_private.normalize({object, apiUrl, client}));
|
||||
});
|
||||
|
||||
common.events.onMany([
|
||||
'post.rescheduled',
|
||||
'page.rescheduled'
|
||||
], function (object) {
|
||||
adapter.reschedule(_private.normalize({object: object, apiUrl: apiUrl, client: client}));
|
||||
], (object) => {
|
||||
adapter.reschedule(_private.normalize({object, apiUrl, client}));
|
||||
});
|
||||
|
||||
common.events.onMany([
|
||||
'post.unscheduled',
|
||||
'page.unscheduled'
|
||||
], function (object) {
|
||||
adapter.unschedule(_private.normalize({object: object, apiUrl: apiUrl, client: client}));
|
||||
], (object) => {
|
||||
adapter.unschedule(_private.normalize({object, apiUrl, client}));
|
||||
});
|
||||
});
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user