Skip to content

Commit

Permalink
fix(download): Optimize download logic and adapt to iframe (#739)
Browse files Browse the repository at this point in the history
* fix(download): Optimize download logic and adapt to iframe
  • Loading branch information
wenmine authored Aug 16, 2024
1 parent 1ed9198 commit 59eaf03
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions packages/utils/src/fs/fszip.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ import JSZIP from 'jszip'
* @param {string} fileName 文件名
*/
export function saveAs(blobData, fileName) {
const zipLink = document.createElement('a')
zipLink.download = fileName
zipLink.style.display = 'none'
zipLink.href = URL.createObjectURL(blobData)
document.body.appendChild(zipLink)
zipLink.click()
document.body.removeChild(zipLink)
const downloadLink = document.createElement('a')
downloadLink.download = fileName
downloadLink.style.display = 'none'
downloadLink.href = URL.createObjectURL(blobData)
document.body.appendChild(downloadLink)
downloadLink.click()
document.body.removeChild(downloadLink)
}

/**
Expand Down
6 changes: 3 additions & 3 deletions packages/utils/src/fs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const isSupportFileSystemAccess =
* @returns dirHandle 目录句柄
*/
export const getUserBaseDirHandle = async (options = {}) => {
if (!window.showOpenFilePicker) {
if (!isSupportFileSystemAccess) {
return createZip()
}
const dirHandle = await window.showDirectoryPicker({ mode: 'readwrite', ...options })
Expand Down Expand Up @@ -81,8 +81,8 @@ export async function getFileHandle(baseDirHandle, filePath, { create = false }
* @returns fileHandle 文件句柄
*/
export const getUserFileHandle = async (options = {}) => {
if (!window.showOpenFilePicker) {
throw new Error('不支持的浏览器!')
if (!isSupportFileSystemAccess) {
throw new Error('不支持的浏览器或处于iframe中')
}
const [fileHandle] = await window.showOpenFilePicker({ mode: 'readwrite', ...options })
return fileHandle
Expand Down

0 comments on commit 59eaf03

Please sign in to comment.