mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Customised key generation for Posts Content API
refs https://github.com/TryGhost/Arch/issues/83 The options included are the only ones which have an effect on the response data, as well as that we are using the properties of members which are used by content-gating module. For the read operation we need to include the ID too.
This commit is contained in:
parent
cfef41cd8f
commit
e865f57e88
1 changed files with 63 additions and 0 deletions
|
@ -23,6 +23,34 @@ const rejectPrivateFieldsTransformer = input => mapQuery(input, function (value,
|
|||
};
|
||||
});
|
||||
|
||||
function generateOptionsData(frame, options) {
|
||||
return options.reduce((memo, option) => {
|
||||
let value = frame.options?.[option];
|
||||
if (['include', 'fields', 'formats'].includes(option)) {
|
||||
value = value?.split(',').sort();
|
||||
}
|
||||
|
||||
if (option === 'page') {
|
||||
value = value || 1;
|
||||
}
|
||||
|
||||
return {
|
||||
...memo,
|
||||
[option]: value
|
||||
};
|
||||
}, {});
|
||||
}
|
||||
|
||||
function generateAuthData(frame) {
|
||||
if (frame.options?.context?.member) {
|
||||
return {
|
||||
free: frame.options?.context?.member.status === 'free',
|
||||
tiers: frame.options?.context?.member.products?.map((product) => {
|
||||
return product.slug;
|
||||
}).sort()
|
||||
};
|
||||
}
|
||||
}
|
||||
module.exports = {
|
||||
docName: 'posts',
|
||||
|
||||
|
@ -31,6 +59,23 @@ module.exports = {
|
|||
cacheInvalidate: false
|
||||
},
|
||||
cache: postsPublicService.api?.cache,
|
||||
generateCacheKeyData(frame) {
|
||||
return {
|
||||
options: generateOptionsData(frame, [
|
||||
'include',
|
||||
'filter',
|
||||
'fields',
|
||||
'formats',
|
||||
'limit',
|
||||
'order',
|
||||
'page',
|
||||
'absolute_urls',
|
||||
'collection'
|
||||
]),
|
||||
auth: generateAuthData(frame),
|
||||
method: 'browse'
|
||||
};
|
||||
},
|
||||
options: [
|
||||
'include',
|
||||
'filter',
|
||||
|
@ -67,6 +112,24 @@ module.exports = {
|
|||
headers: {
|
||||
cacheInvalidate: false
|
||||
},
|
||||
cache: postsPublicService.api?.cache,
|
||||
generateCacheKeyData(frame) {
|
||||
return {
|
||||
options: generateOptionsData(frame, [
|
||||
'include',
|
||||
'fields',
|
||||
'formats',
|
||||
'absolute_urls'
|
||||
]),
|
||||
auth: generateAuthData(frame),
|
||||
method: 'read',
|
||||
identifier: {
|
||||
id: frame.data.id,
|
||||
slug: frame.data.slug,
|
||||
uuid: frame.data.uuid
|
||||
}
|
||||
};
|
||||
},
|
||||
options: [
|
||||
'include',
|
||||
'fields',
|
||||
|
|
Loading…
Add table
Reference in a new issue