@cloudbase/utilities
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -98,17 +98,31 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var fileName, link; | ||
var data, url, fileName, link, e_1; | ||
return __generator(this, function (_a) { | ||
fileName = decodeURIComponent(new URL(options.url).pathname.split('/').pop() || ''); | ||
link = document.createElement('a'); | ||
link.href = options.url; | ||
link.setAttribute('download', fileName); | ||
link.setAttribute('target', '_blank'); | ||
document.body.appendChild(link); | ||
link.click(); | ||
return [2, new Promise(function (resolve) { | ||
resolve({ | ||
statusCode: 200, | ||
tempFilePath: options.url | ||
}); | ||
})]; | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4, this.get(__assign(__assign({}, options), { headers: {}, responseType: 'blob' }))]; | ||
case 1: | ||
data = (_a.sent()).data; | ||
url = window.URL.createObjectURL(new Blob([data])); | ||
fileName = decodeURIComponent(new URL(options.url).pathname.split('/').pop() || ''); | ||
link = document.createElement('a'); | ||
link.href = url; | ||
link.setAttribute('download', fileName); | ||
link.style.display = 'none'; | ||
document.body.appendChild(link); | ||
link.click(); | ||
window.URL.revokeObjectURL(url); | ||
document.body.removeChild(link); | ||
return [3, 3]; | ||
case 2: | ||
e_1 = _a.sent(); | ||
return [3, 3]; | ||
case 3: return [2, new Promise(function (resolve) { | ||
resolve({ | ||
statusCode: 200, | ||
tempFilePath: options.url | ||
}); | ||
})]; | ||
} | ||
}); | ||
@@ -149,6 +163,6 @@ }); | ||
try { | ||
result.data = JSON.parse(ajax.responseText); | ||
result.data = responseType === 'blob' ? ajax.response : JSON.parse(ajax.responseText); | ||
} | ||
catch (e) { | ||
result.data = ajax.responseText; | ||
result.data = responseType === 'blob' ? ajax.response : ajax.responseText; | ||
} | ||
@@ -155,0 +169,0 @@ clearTimeout(timer); |
{ | ||
"name": "@cloudbase/utilities", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "cloudbase javascript sdk utilities", | ||
@@ -49,3 +49,3 @@ "main": "dist/index.js", | ||
}, | ||
"gitHead": "3898802234fd2550f6dbe7faa68d0ca3f4cd94f3" | ||
"gitHead": "9e5a8e510117de60e9deca7b39dad841b54eb3d0" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
45325
1051