mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Refactored headers function to use async/await
no issue - The async/await syntax makes it easier to reason about the code. Because adding 'Location' header is in the works it's a prep-work in a sense
This commit is contained in:
parent
2d2fa1a0ba
commit
4606c93e4f
1 changed files with 15 additions and 30 deletions
|
@ -101,41 +101,26 @@ module.exports = {
|
|||
* @param {Object} apiConfig
|
||||
* @return {Promise}
|
||||
*/
|
||||
get(result, apiConfig = {}) {
|
||||
async get(result, apiConfig = {}) {
|
||||
let headers = {};
|
||||
|
||||
return Promise.resolve()
|
||||
.then(() => {
|
||||
let header;
|
||||
if (apiConfig.disposition) {
|
||||
const dispositionHeader = await disposition[apiConfig.disposition.type](result, apiConfig.disposition);
|
||||
|
||||
if (apiConfig.disposition) {
|
||||
header = disposition[apiConfig.disposition.type](result, apiConfig.disposition);
|
||||
}
|
||||
if (dispositionHeader) {
|
||||
Object.assign(headers, dispositionHeader);
|
||||
}
|
||||
}
|
||||
|
||||
return header;
|
||||
})
|
||||
.then((header) => {
|
||||
if (header) {
|
||||
Object.assign(headers, header);
|
||||
}
|
||||
})
|
||||
.then(() => {
|
||||
let header;
|
||||
if (apiConfig.cacheInvalidate) {
|
||||
const cacheInvalidationHeader = cacheInvalidate(result, apiConfig.cacheInvalidate);
|
||||
|
||||
if (apiConfig.cacheInvalidate) {
|
||||
header = cacheInvalidate(result, apiConfig.cacheInvalidate);
|
||||
}
|
||||
if (cacheInvalidationHeader) {
|
||||
Object.assign(headers, cacheInvalidationHeader);
|
||||
}
|
||||
}
|
||||
|
||||
return header;
|
||||
})
|
||||
.then((header) => {
|
||||
if (header) {
|
||||
Object.assign(headers, header);
|
||||
}
|
||||
})
|
||||
.then(() => {
|
||||
debug(headers);
|
||||
return headers;
|
||||
});
|
||||
debug(headers);
|
||||
return headers;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue