0
Fork 0
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:
Nazar Gargol 2020-09-07 15:36:06 +12:00
parent 2d2fa1a0ba
commit 4606c93e4f

View file

@ -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;
}
};