mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 01:41:46 +03:00
e8ad189511
refs: TryGhost#13380 - The i18n package is deprecated. It is being replaced with the tpl package.
75 lines
1.9 KiB
JavaScript
75 lines
1.9 KiB
JavaScript
const models = require('../../models');
|
|
const tpl = require('@tryghost/tpl');
|
|
const errors = require('@tryghost/errors');
|
|
const mega = require('../../services/mega');
|
|
|
|
const messages = {
|
|
postNotFound: 'Post not found.'
|
|
};
|
|
|
|
const emailPreview = new mega.EmailPreview({
|
|
apiVersion: 'v3'
|
|
});
|
|
|
|
module.exports = {
|
|
docName: 'email_preview',
|
|
|
|
read: {
|
|
options: [
|
|
'fields'
|
|
],
|
|
validation: {
|
|
options: {
|
|
fields: ['html', 'plaintext', 'subject']
|
|
}
|
|
},
|
|
data: [
|
|
'id',
|
|
'status'
|
|
],
|
|
permissions: true,
|
|
async query(frame) {
|
|
const options = Object.assign(frame.options, {formats: 'html,plaintext', withRelated: ['authors', 'posts_meta']});
|
|
const data = Object.assign(frame.data, {status: 'all'});
|
|
|
|
const model = await models.Post.findOne(data, options);
|
|
|
|
if (!model) {
|
|
throw new errors.NotFoundError({
|
|
message: tpl(messages.postNotFound)
|
|
});
|
|
}
|
|
|
|
return emailPreview.generateEmailContent(model, frame.options.memberSegment);
|
|
}
|
|
},
|
|
sendTestEmail: {
|
|
statusCode: 200,
|
|
headers: {},
|
|
options: [
|
|
'id'
|
|
],
|
|
validation: {
|
|
options: {
|
|
id: {
|
|
required: true
|
|
}
|
|
}
|
|
},
|
|
permissions: true,
|
|
async query(frame) {
|
|
const options = Object.assign(frame.options, {status: 'all'});
|
|
let model = await models.Post.findOne(options, {withRelated: ['authors']});
|
|
|
|
if (!model) {
|
|
throw new errors.NotFoundError({
|
|
message: tpl(messages.postNotFound)
|
|
});
|
|
}
|
|
|
|
const {emails = []} = frame.data;
|
|
return await mega.mega.sendTestEmail(model, emails, 'v3');
|
|
}
|
|
}
|
|
};
|