Commit 7f3319bd authored by gxkai's avatar gxkai

chore: 下载空间

parent 3a57fc43
...@@ -235,14 +235,17 @@ const saveAs = (blob, name) => { ...@@ -235,14 +235,17 @@ const saveAs = (blob, name) => {
} }
}, 0) // 40s }, 0) // 40s
} }
// todo 下载文件夹 // todo 选中目标下载
export const downloadFile = async (folder?: string) => { export const downloadFile = async (folder?: string ) => {
try { try {
tooltip('preparing files for download, please wait..') tooltip('preparing files for download, please wait..')
const fileProviders = globalRegistry.get('fileproviders').api const fileProviders = globalRegistry.get('fileproviders').api
const zip = new JSZip() const zip = new JSZip()
await fileProviders.browser.copyFolderToJson(`/`, ({ path, content }) => { await fileProviders.browser.copyFolderToJson(`/`, ({ path, content }) => {
zip.file(`${folder}${path}`, content) const path$ = path.replace(/\/([^\/]*)\//, '')
if (path$.startsWith(folder)) {
zip.file(path$, content)
}
}) })
zip.generateAsync({ type: 'blob' }).then(function (blob) { zip.generateAsync({ type: 'blob' }).then(function (blob) {
saveAs(blob, `${folder}.zip`) saveAs(blob, `${folder}.zip`)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment