From e987e0ad56f58dbc401daa81d6cb53acd66ecbd7 Mon Sep 17 00:00:00 2001 From: Robson Sobral Date: Wed, 2 Sep 2020 18:58:01 -0300 Subject: [PATCH] Download log response --- source/scripts/index.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/source/scripts/index.js b/source/scripts/index.js index 9632f6cf..5f2222ee 100644 --- a/source/scripts/index.js +++ b/source/scripts/index.js @@ -153,6 +153,20 @@ window.$vue = new Vue({ }).then((response) => { if (response.body.request_url) { window.location = response.body.request_url; + } else if (response.headers.get('content-type') + && response.headers.get('content-type').indexOf('application/octet-stream') !== -1 + ) { + const url = window.URL.createObjectURL(new Blob([response.body])); + const link = document.createElement('a'); + const filename = response.headers.get('content-disposition') + .split('filename=')[1] + .split(';')[0] + .replace('"', ''); + + link.href = url; + link.setAttribute('download', filename); + document.body.appendChild(link); + link.click(); } else { if (response.body.metadata.error) { window.alert(response.body.metadata.error); // eslint-disable-line no-alert @@ -198,6 +212,8 @@ window.$vue = new Vue({ this.metadata.loading = false; } } + + this.metadata.loading = false; }, (error) => { console.log('error', error); // eslint-disable-line no-console this.cancelRequest(); @@ -288,6 +304,7 @@ window.$vue = new Vue({ if (this.metadata.query.verbose) { params.verbose = this.metadata.query.verbose; + params.responseType = 'blob'; } if (this.metadata.query.search_for === 'profile') {