-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using content-disposition
pkg for non-US font titles in reporting
#30895
Merged
joelgriffith
merged 6 commits into
elastic:master
from
joelgriffith:reporting-bugfix-handle-content-disposition
Feb 21, 2019
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f0beb28
Using content-disposition for non-US font titles in reporting
8b44cb6
Fixing test failures (actual regression)
d90ed8a
Fixing lib import
3dd9f77
Moving content-disposition over to x-pack package.json
05007e0
deps not dev deps...
bcc49ee
Small util for generating report name
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,20 @@ | |
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
// @ts-ignore | ||
import contentDisposition from 'content-disposition'; | ||
// @ts-ignore | ||
import { oncePerServer } from '../../lib/once_per_server'; | ||
|
||
function getDocumentPayloadFn(server) { | ||
const DEFAULT_TITLE = 'report'; | ||
|
||
const getTitle = (exportType: any, title?: string): string => | ||
`${title || DEFAULT_TITLE}.${exportType.jobContentExtension}`; | ||
|
||
function getDocumentPayloadFn(server: any) { | ||
const exportTypesRegistry = server.plugins.reporting.exportTypesRegistry; | ||
|
||
function encodeContent(content, exportType) { | ||
function encodeContent(content: string, exportType: any) { | ||
switch (exportType.jobContentEncoding) { | ||
case 'base64': | ||
return Buffer.from(content, 'base64'); | ||
|
@@ -18,42 +26,44 @@ function getDocumentPayloadFn(server) { | |
} | ||
} | ||
|
||
function getCompleted(output, jobType, title) { | ||
const exportType = exportTypesRegistry.get(item => item.jobType === jobType); | ||
function getCompleted(output: any, jobType: string, title: any) { | ||
const exportType = exportTypesRegistry.get((item: any) => item.jobType === jobType); | ||
const filename = getTitle(exportType, title); | ||
|
||
return { | ||
statusCode: 200, | ||
content: encodeContent(output.content, exportType), | ||
contentType: output.content_type, | ||
headers: { | ||
'Content-Disposition': `inline; filename="${title || 'report'}.${exportType.jobContentExtension}"` | ||
} | ||
'Content-Disposition': contentDisposition(filename, { type: 'inline' }), | ||
}, | ||
}; | ||
} | ||
|
||
function getFailure(output) { | ||
function getFailure(output: any) { | ||
return { | ||
statusCode: 500, | ||
content: { | ||
message: 'Reporting generation failed', | ||
reason: output.content | ||
reason: output.content, | ||
}, | ||
contentType: 'application/json' | ||
contentType: 'application/json', | ||
}; | ||
} | ||
|
||
function getIncomplete(status) { | ||
function getIncomplete(status: any) { | ||
return { | ||
statusCode: 503, | ||
content: status, | ||
contentType: 'application/json', | ||
headers: { | ||
'retry-after': 30 | ||
} | ||
'retry-after': 30, | ||
}, | ||
}; | ||
} | ||
|
||
return function getDocumentPayload(doc) { | ||
const { status, output, jobtype: jobType, payload: { title } = {} } = doc._source; | ||
return function getDocumentPayload(doc: any) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After #31188 goes in, we can replace the |
||
const { status, output, jobtype: jobType, payload: { title } = { title: '' } } = doc._source; | ||
|
||
if (status === 'completed') { | ||
return getCompleted(output, jobType, title); | ||
|
@@ -69,4 +79,3 @@ function getDocumentPayloadFn(server) { | |
} | ||
|
||
export const getDocumentPayloadFactory = oncePerServer(getDocumentPayloadFn); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7044,6 +7044,13 @@ [email protected]: | |
resolved "https://registry.yarnpkg.com/content-disposition/-/content-disposition-0.5.2.tgz#0cf68bb9ddf5f2be7961c3a85178cb85dba78cb4" | ||
integrity sha1-DPaLud318r55YcOoUXjLhdunjLQ= | ||
|
||
[email protected]: | ||
version "0.5.3" | ||
resolved "https://registry.yarnpkg.com/content-disposition/-/content-disposition-0.5.3.tgz#e130caf7e7279087c5616c2007d0485698984fbd" | ||
integrity sha512-ExO0774ikEObIAEV9kDo50o+79VCUdEB6n6lzKgGwupcVeRlhrj3qGAfwq8G6uBJjkqLrhT0qEYFcWng8z1z0g== | ||
dependencies: | ||
safe-buffer "5.1.2" | ||
|
||
content-type-parser@^1.0.1: | ||
version "1.0.2" | ||
resolved "https://registry.yarnpkg.com/content-type-parser/-/content-type-parser-1.0.2.tgz#caabe80623e63638b2502fd4c7f12ff4ce2352e7" | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated change automatically done by
yarn
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, likely just wasn't properly alphabetized before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might as well leave it in, it'll just end up as an unrelated change in some other PR :D