mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Added MEGA service (#11333)
no issue - This services listens to 'post.publish' event, assemples email data and calls bulk mailer
This commit is contained in:
parent
82e022b582
commit
74f2145e81
2 changed files with 41 additions and 1 deletions
|
@ -28,6 +28,7 @@ function initialiseServices() {
|
||||||
apps = require('./services/apps'),
|
apps = require('./services/apps'),
|
||||||
xmlrpc = require('./services/xmlrpc'),
|
xmlrpc = require('./services/xmlrpc'),
|
||||||
slack = require('./services/slack'),
|
slack = require('./services/slack'),
|
||||||
|
mega = require('./services/mega'),
|
||||||
webhooks = require('./services/webhooks'),
|
webhooks = require('./services/webhooks'),
|
||||||
scheduling = require('./adapters/scheduling');
|
scheduling = require('./adapters/scheduling');
|
||||||
|
|
||||||
|
@ -38,6 +39,7 @@ function initialiseServices() {
|
||||||
permissions.init(),
|
permissions.init(),
|
||||||
xmlrpc.listen(),
|
xmlrpc.listen(),
|
||||||
slack.listen(),
|
slack.listen(),
|
||||||
|
mega.listen(),
|
||||||
webhooks.listen(),
|
webhooks.listen(),
|
||||||
apps.init(),
|
apps.init(),
|
||||||
scheduling.init({
|
scheduling.init({
|
||||||
|
@ -50,7 +52,7 @@ function initialiseServices() {
|
||||||
contentPath: config.getContentPath('scheduling')
|
contentPath: config.getContentPath('scheduling')
|
||||||
})
|
})
|
||||||
).then(function () {
|
).then(function () {
|
||||||
debug('XMLRPC, Slack, Webhooks, Apps, Scheduling, Permissions done');
|
debug('XMLRPC, Slack, MEGA, Webhooks, Apps, Scheduling, Permissions done');
|
||||||
|
|
||||||
// Initialise analytics events
|
// Initialise analytics events
|
||||||
if (config.get('segment:key')) {
|
if (config.get('segment:key')) {
|
||||||
|
|
38
core/server/services/mega.js
Normal file
38
core/server/services/mega.js
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
const common = require('../lib/common');
|
||||||
|
const membersService = require('./members');
|
||||||
|
const bulkEmailService = require('./bulk-email');
|
||||||
|
|
||||||
|
const sendEmail = async (post) => {
|
||||||
|
const emailTmpl = {
|
||||||
|
subject: post.email_subject || post.title,
|
||||||
|
html: post.html
|
||||||
|
};
|
||||||
|
|
||||||
|
const {members} = await membersService.api.members.list();
|
||||||
|
const emails = members.map(m => m.email);
|
||||||
|
|
||||||
|
return bulkEmailService.send(emailTmpl, emails);
|
||||||
|
};
|
||||||
|
|
||||||
|
function listener(model, options) {
|
||||||
|
// CASE: do not ping slack if we import a database
|
||||||
|
// TODO: refactor post.published events to never fire on importing
|
||||||
|
if (options && options.importing) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!model.get('send_email_when_published')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sendEmail(model.toJSON());
|
||||||
|
}
|
||||||
|
|
||||||
|
function listen() {
|
||||||
|
common.events.on('post.published', listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Public API
|
||||||
|
module.exports = {
|
||||||
|
listen: listen
|
||||||
|
};
|
Loading…
Add table
Reference in a new issue