Improve type detection

We use blob.type property to detect the content-type
This commit is contained in:
Julien Fastré 2017-04-19 14:24:34 +02:00
parent bf12046afa
commit b6d1f05e00

View File

@ -25,8 +25,7 @@
window.addEventListener("DOMContentLoaded", function(e) {
var url = "{{ path('chill_main_export_generate', { 'alias' : alias } ) }}",
query = window.location.search,
container = document.querySelector("#download_container"),
header_content_type
container = document.querySelector("#download_container")
;
window.fetch(url+query, { credentials: 'same-origin' })
@ -34,14 +33,14 @@ window.addEventListener("DOMContentLoaded", function(e) {
if (!response.ok) {
throw Error(response.statusText);
}
header_content_type = response.headers.get("Content-Type");
return response.blob();
}).then(function(blob) {
var content = URL.createObjectURL(blob),
link = document.createElement("a"),
suffix_file;
switch (header_content_type) {
switch (blob.type) {
case 'application/vnd.oasis.opendocument.spreadsheet':
suffix_file = '.ods';
break;