mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Refactored content-disposition header handling in API v2 (#10374)
closes https://github.com/TryGhost/Ghost/issues/10331 - Left only a filename part to be handled by controller configuration, the rest was extracted to more generic headers layer
This commit is contained in:
parent
ceeb78b85b
commit
48d6e7298a
4 changed files with 8 additions and 8 deletions
|
@ -18,14 +18,14 @@ const disposition = {
|
|||
}
|
||||
|
||||
return {
|
||||
'Content-Disposition': value,
|
||||
'Content-Disposition': `Attachment; filename="${value}"`,
|
||||
'Content-Type': 'text/csv'
|
||||
};
|
||||
},
|
||||
|
||||
json(result, options = {}) {
|
||||
return {
|
||||
'Content-Disposition': options.value,
|
||||
'Content-Disposition': `Attachment; filename="${options.value}"`,
|
||||
'Content-Type': 'application/json',
|
||||
'Content-Length': Buffer.byteLength(JSON.stringify(result))
|
||||
};
|
||||
|
@ -33,7 +33,7 @@ const disposition = {
|
|||
|
||||
yaml(result, options = {}) {
|
||||
return {
|
||||
'Content-Disposition': options.value,
|
||||
'Content-Disposition': `Attachment; filename="${options.value}"`,
|
||||
'Content-Type': 'application/yaml',
|
||||
'Content-Length': Buffer.byteLength(JSON.stringify(result))
|
||||
};
|
||||
|
|
|
@ -177,7 +177,7 @@ module.exports = {
|
|||
headers: {
|
||||
disposition: {
|
||||
type: 'yaml',
|
||||
value: 'Attachment; filename="routes.yaml"'
|
||||
value: 'routes.yaml'
|
||||
}
|
||||
},
|
||||
response: {
|
||||
|
|
|
@ -143,7 +143,7 @@ const subscribers = {
|
|||
type: 'csv',
|
||||
value() {
|
||||
const datetime = (new Date()).toJSON().substring(0, 10);
|
||||
return `Attachment; filename="subscribers.${datetime}.csv"`;
|
||||
return `subscribers.${datetime}.csv`;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -13,7 +13,7 @@ describe('Unit: api/shared/headers', function () {
|
|||
return shared.headers.get({}, {disposition: {type: 'json', value: 'value'}})
|
||||
.then(result => {
|
||||
result.should.eql({
|
||||
'Content-Disposition': 'value',
|
||||
'Content-Disposition': 'Attachment; filename=\"value\"',
|
||||
'Content-Type': 'application/json',
|
||||
'Content-Length': 2
|
||||
});
|
||||
|
@ -24,7 +24,7 @@ describe('Unit: api/shared/headers', function () {
|
|||
return shared.headers.get({}, {disposition: {type: 'csv', value: 'my.csv'}})
|
||||
.then(result => {
|
||||
result.should.eql({
|
||||
'Content-Disposition': 'my.csv',
|
||||
'Content-Disposition': 'Attachment; filename=\"my.csv\"',
|
||||
'Content-Type': 'text/csv'
|
||||
});
|
||||
});
|
||||
|
@ -34,7 +34,7 @@ describe('Unit: api/shared/headers', function () {
|
|||
return shared.headers.get('yaml file', {disposition: {type: 'yaml', value: 'my.yaml'}})
|
||||
.then(result => {
|
||||
result.should.eql({
|
||||
'Content-Disposition': 'my.yaml',
|
||||
'Content-Disposition': 'Attachment; filename=\"my.yaml\"',
|
||||
'Content-Type': 'application/yaml',
|
||||
'Content-Length': 11
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue