Skip to content

Commit

Permalink
Merge pull request #38 from cloverstd/master
Browse files Browse the repository at this point in the history
Add image preview
  • Loading branch information
lujjjh committed Jul 3, 2019
2 parents a69f133 + d772a7f commit 75c1f86
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion faas/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,28 @@
}
}

class ResponseViewImage extends Jinkela {
beforeParse(params) {
if (!params.filename) {
params.filename = '';
}
}
get template() {
return `
<a download="{filename}" href="{url}">
<img src="{url}"/>
</a>
`;
}
get styleSheet() {
return `
:scope {
text-decoration: none;
}
`;
}
}

class ResponseViewDownloadLink extends Jinkela {
beforeParse(params) {
if (!params.filename) {
Expand Down Expand Up @@ -285,6 +307,7 @@
let json = /json/.test(contentType);
let javascript = /javascript/.test(contentType);
let binary = !(/text/.test(contentType) || json || javascript);
let image = /image/.test(contentType);
let contentDisposition = response.headers.get('Content-Disposition') || '';
try {
contentDisposition = ContentDispositionAttachment.parse(contentDisposition);
Expand All @@ -293,7 +316,11 @@
}
let { attachment, filename } = contentDisposition;
let $body;
if (binary || attachment) {
if (image) {
$body = response.blob().then(URL.createObjectURL).then(url => {
return { elements: [ new ResponseViewImage({ url, filename }) ] };
});
} else if (binary || attachment) {
$body = response.blob().then(URL.createObjectURL).then(url => {
return { elements: [ new ResponseViewDownloadLink({ url, filename }) ] };
});
Expand Down

0 comments on commit 75c1f86

Please sign in to comment.