Skip to content

Commit a11e544

Browse files
author
Bruno Tremblay
authored
pr review
I'll try to come up with an example
1 parent 17864c4 commit a11e544

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

src/components/api-request.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,11 @@ export default class ApiRequest extends LitElement {
677677
${this.responseIsBlob
678678
? html`
679679
<div class="tab-content col" style="flex:1; display:${this.activeResponseTab === 'response' ? 'flex' : 'none'};">
680-
<button class="m-btn" @click="${this.downloadResponseBlob}">${this.responseBlobType.toUpperCase()}</button>
680+
<button class="m-btn" @click="${this.downloadResponseBlob}">DOWNLOAD</button>
681+
${this.responseBlobType === 'view'
682+
? html`<button class="m-btn" @click="${this.viewResponseBlob}">VIEW (NEW TAB)</button>`
683+
: ''
684+
}
681685
</div>`
682686
: html`
683687
<div class="tab-content col m-markdown" style="flex:1;display:${this.activeResponseTab === 'response' ? 'flex' : 'none'};" >
@@ -1003,20 +1007,20 @@ export default class ApiRequest extends LitElement {
10031007
resp.json().then((respObj) => {
10041008
me.responseText = JSON.stringify(respObj, null, 2);
10051009
});
1006-
} else if (RegExp('7z|octet-stream|pdf|tar|zip').test(contentType)) {
1010+
} else if (RegExp('7z|octet-stream|tar|zip').test(contentType)) {
10071011
me.responseIsBlob = true;
10081012
me.responseBlobType = 'download';
1009-
const contentDisposition = resp.headers.get('content-disposition');
1010-
me.respContentDisposition = contentDisposition ? contentDisposition.split('filename=')[1] : 'filename';
1011-
} else if (RegExp('^audio|^image|^video').test(contentType)) {
1013+
} else if (RegExp('^audio|^image|pdf|^video').test(contentType)) {
10121014
me.responseIsBlob = true;
1013-
me.responseBlobType = 'show';
1015+
me.responseBlobType = 'view';
10141016
} else {
10151017
resp.text().then((respText) => {
10161018
me.responseText = respText;
10171019
});
10181020
}
10191021
if (me.responseIsBlob) {
1022+
const contentDisposition = resp.headers.get('content-disposition');
1023+
me.respContentDisposition = contentDisposition ? contentDisposition.split('filename=')[1] : 'filename';
10201024
resp.blob().then((respBlob) => {
10211025
me.responseBlobUrl = URL.createObjectURL(respBlob);
10221026
});
@@ -1077,11 +1081,19 @@ export default class ApiRequest extends LitElement {
10771081
document.body.appendChild(a);
10781082
a.style = 'display: none';
10791083
a.href = this.responseBlobUrl;
1080-
if (this.responseBlobType === 'show') {
1081-
a.target = '_blank';
1082-
} else {
1083-
a.download = this.respContentDisposition;
1084-
}
1084+
a.download = this.respContentDisposition;
1085+
a.click();
1086+
a.remove();
1087+
}
1088+
}
1089+
1090+
viewResponseBlob() {
1091+
if (this.responseBlobUrl) {
1092+
const a = document.createElement('a');
1093+
document.body.appendChild(a);
1094+
a.style = 'display: none';
1095+
a.href = this.responseBlobUrl;
1096+
a.target = '_blank';
10851097
a.click();
10861098
a.remove();
10871099
}

0 commit comments

Comments
 (0)