Skip to content

Commit

Permalink
perf: Firefox unable to download file
Browse files Browse the repository at this point in the history
  • Loading branch information
feng626 authored and BaiJiangJie committed Dec 26, 2024
1 parent 9efccb8 commit df26679
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions src/utils/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,16 +366,32 @@ export function download(downloadUrl, filename) {
const iframe = document.createElement('iframe')
iframe.style.display = 'none'
document.body.appendChild(iframe)
const a = document.createElement('a')
a.href = downloadUrl
const timeout = 1000 * 60 * 30

if (filename) {
a.download = filename
fetch(downloadUrl)
.then(response => response.blob())
.then(blob => {
const url = URL.createObjectURL(blob)
const a = iframe.contentWindow.document.createElement('a')
a.href = url
a.download = filename
iframe.contentWindow.document.body.appendChild(a)
a.click()
setTimeout(() => {
URL.revokeObjectURL(url)
document.body.removeChild(iframe)
}, timeout) // If you can't download it in half an hour, don't download it.
})
.catch(() => {
document.body.removeChild(iframe)
})
} else {
iframe.src = downloadUrl
setTimeout(() => {
document.body.removeChild(iframe)
}, timeout) // If you can't download it in half an hour, don't download it.
}
iframe.contentWindow.document.body.appendChild(a)
a.click()
setTimeout(() => {
document.body.removeChild(iframe)
}, 1000 * 60 * 30) // If you can't download it in half an hour, don't download it.
}

export function diffObject(object, base) {
Expand Down

0 comments on commit df26679

Please sign in to comment.