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:
|
* scheduling modules:
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
var Promise = require('bluebird'),
|
const Promise = require('bluebird'),
|
||||||
moment = require('moment'),
|
moment = require('moment'),
|
||||||
localUtils = require('../utils'),
|
localUtils = require('../utils'),
|
||||||
common = require('../../../lib/common'),
|
common = require('../../../lib/common'),
|
||||||
@ -8,13 +8,11 @@ var Promise = require('bluebird'),
|
|||||||
_private = {};
|
_private = {};
|
||||||
|
|
||||||
_private.normalize = function normalize(options) {
|
_private.normalize = function normalize(options) {
|
||||||
var object = options.object,
|
const {object, apiUrl, client} = options;
|
||||||
apiUrl = options.apiUrl,
|
|
||||||
client = options.client;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
time: moment(object.get('published_at')).valueOf(),
|
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: {
|
extra: {
|
||||||
httpMethod: 'PUT',
|
httpMethod: 'PUT',
|
||||||
oldTime: object.updated('published_at') ? moment(object.updated('published_at')).valueOf() : null
|
oldTime: object.updated('published_at') ? moment(object.updated('published_at')).valueOf() : null
|
||||||
@ -28,18 +26,17 @@ _private.loadClient = function loadClient() {
|
|||||||
|
|
||||||
_private.loadScheduledPosts = function () {
|
_private.loadScheduledPosts = function () {
|
||||||
return schedules.getScheduledPosts()
|
return schedules.getScheduledPosts()
|
||||||
.then(function (result) {
|
.then((result) => {
|
||||||
return result.posts || [];
|
return result.posts || [];
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.init = function init(options) {
|
exports.init = function init(options = {}) {
|
||||||
var config = options || {},
|
const {apiUrl} = options;
|
||||||
apiUrl = config.apiUrl,
|
let adapter = null,
|
||||||
adapter = null,
|
|
||||||
client = null;
|
client = null;
|
||||||
|
|
||||||
if (!config) {
|
if (!Object.keys(options).length) {
|
||||||
return Promise.reject(new common.errors.IncorrectUsageError({message: 'post-scheduling: no config was provided'}));
|
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()
|
return _private.loadClient()
|
||||||
.then(function (_client) {
|
.then((_client) => {
|
||||||
client = _client;
|
client = _client;
|
||||||
return localUtils.createAdapter(config);
|
return localUtils.createAdapter(options);
|
||||||
})
|
})
|
||||||
.then(function (_adapter) {
|
.then((_adapter) => {
|
||||||
adapter = _adapter;
|
adapter = _adapter;
|
||||||
if (!adapter.rescheduleOnBoot) {
|
if (!adapter.rescheduleOnBoot) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
return _private.loadScheduledPosts();
|
return _private.loadScheduledPosts();
|
||||||
})
|
})
|
||||||
.then(function (scheduledPosts) {
|
.then((scheduledPosts) => {
|
||||||
if (!scheduledPosts.length) {
|
if (!scheduledPosts.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
scheduledPosts.forEach(function (object) {
|
scheduledPosts.forEach((object) => {
|
||||||
adapter.reschedule(_private.normalize({object: object, apiUrl: apiUrl, client: client}));
|
adapter.reschedule(_private.normalize({object, apiUrl, client}));
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then(function () {
|
.then(() => {
|
||||||
adapter.run();
|
adapter.run();
|
||||||
})
|
})
|
||||||
.then(function () {
|
.then(() => {
|
||||||
common.events.onMany([
|
common.events.onMany([
|
||||||
'post.scheduled',
|
'post.scheduled',
|
||||||
'page.scheduled'
|
'page.scheduled'
|
||||||
], function (object) {
|
], (object) => {
|
||||||
adapter.schedule(_private.normalize({object: object, apiUrl: apiUrl, client: client}));
|
adapter.schedule(_private.normalize({object, apiUrl, client}));
|
||||||
});
|
});
|
||||||
|
|
||||||
common.events.onMany([
|
common.events.onMany([
|
||||||
'post.rescheduled',
|
'post.rescheduled',
|
||||||
'page.rescheduled'
|
'page.rescheduled'
|
||||||
], function (object) {
|
], (object) => {
|
||||||
adapter.reschedule(_private.normalize({object: object, apiUrl: apiUrl, client: client}));
|
adapter.reschedule(_private.normalize({object, apiUrl, client}));
|
||||||
});
|
});
|
||||||
|
|
||||||
common.events.onMany([
|
common.events.onMany([
|
||||||
'post.unscheduled',
|
'post.unscheduled',
|
||||||
'page.unscheduled'
|
'page.unscheduled'
|
||||||
], function (object) {
|
], (object) => {
|
||||||
adapter.unschedule(_private.normalize({object: object, apiUrl: apiUrl, client: client}));
|
adapter.unschedule(_private.normalize({object, apiUrl, client}));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user