mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 11:22:19 +03:00
Added an internal API for email-only posts
refs https://github.com/TryGhost/Team/issues/899 - The internal API is needed to be able to fetch email-only posts through email router. The concept is similar to Preview API with a difference that only posts with `sent` status are accessible and there is content-gating present.
This commit is contained in:
parent
59a60d77b9
commit
0d7f253582
41
core/server/api/canary/email-post.js
Normal file
41
core/server/api/canary/email-post.js
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
const i18n = require('../../../shared/i18n');
|
||||||
|
const errors = require('@tryghost/errors');
|
||||||
|
const models = require('../../models');
|
||||||
|
const ALLOWED_INCLUDES = ['authors', 'tags'];
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
docName: 'email_post',
|
||||||
|
|
||||||
|
read: {
|
||||||
|
permissions: true,
|
||||||
|
options: [
|
||||||
|
'include'
|
||||||
|
],
|
||||||
|
data: [
|
||||||
|
'slug'
|
||||||
|
],
|
||||||
|
validation: {
|
||||||
|
options: {
|
||||||
|
include: {
|
||||||
|
values: ALLOWED_INCLUDES
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
slug: {
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async query(frame) {
|
||||||
|
const model = await models.Post.findOne(Object.assign(frame.data, {status: 'sent'}), frame.options);
|
||||||
|
|
||||||
|
if (!model) {
|
||||||
|
throw new errors.NotFoundError({
|
||||||
|
message: i18n.t('errors.api.posts.postNotFound')
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
@ -107,6 +107,10 @@ module.exports = {
|
|||||||
return shared.pipeline(require('./preview'), localUtils);
|
return shared.pipeline(require('./preview'), localUtils);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
get emailPost() {
|
||||||
|
return shared.pipeline(require('./email-post'), localUtils);
|
||||||
|
},
|
||||||
|
|
||||||
get oembed() {
|
get oembed() {
|
||||||
return shared.pipeline(require('./oembed'), localUtils);
|
return shared.pipeline(require('./oembed'), localUtils);
|
||||||
},
|
},
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
const mapper = require('./utils/mapper');
|
||||||
|
const gating = require('./utils/post-gating');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
read(model, apiConfig, frame) {
|
||||||
|
const emailPost = mapper.mapPost(model, frame);
|
||||||
|
gating.forPost(emailPost, frame);
|
||||||
|
|
||||||
|
frame.response = {
|
||||||
|
email_posts: [emailPost]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
@ -91,6 +91,10 @@ module.exports = {
|
|||||||
return require('./preview');
|
return require('./preview');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
get email_post() {
|
||||||
|
return require('./email-posts');
|
||||||
|
},
|
||||||
|
|
||||||
get oembed() {
|
get oembed() {
|
||||||
return require('./oembed');
|
return require('./oembed');
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user