Update downloader.js

This commit is contained in:
Anthony Stirling 2024-11-20 09:23:41 +00:00 committed by GitHub
parent 9e30918aae
commit b9a014b5c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -167,6 +167,19 @@
}
}
function getFilenameFromContentDisposition(contentDisposition) {
let filename;
if (contentDisposition && contentDisposition.indexOf("attachment") !== -1) {
filename = decodeURIComponent(contentDisposition.split("filename=")[1].replace(/"/g, "")).trim();
} else {
// If the Content-Disposition header is not present or does not contain the filename, use a default filename
filename = "download";
}
return filename;
}
async function handleJsonResponse(response) {
const json = await response.json();
const errorMessage = JSON.stringify(json, null, 2);