From 2c461df5fc25a98c3a00927ca7820e5de284b246 Mon Sep 17 00:00:00 2001 From: awalol Date: Tue, 17 Jun 2025 18:40:58 +0800 Subject: [PATCH] =?UTF-8?q?fix(downloadAll):=20=E9=98=B2=E6=AD=A2=E6=9C=AA?= =?UTF-8?q?=E8=A7=A3=E5=AF=86=E6=96=87=E4=BB=B6=E5=AF=BC=E8=87=B4=E7=9A=84?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E5=A4=B1=E8=B4=A5=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E9=80=89=E6=8B=A9=E6=A1=86=E7=9A=84=E5=BC=B9?= =?UTF-8?q?=E5=87=BA=20=E4=BC=98=E5=8C=96=E6=9D=83=E9=99=90=E8=AF=B7?= =?UTF-8?q?=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/DownloadAll.tsx | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/components/DownloadAll.tsx b/src/components/DownloadAll.tsx index 5975033..5641f0b 100644 --- a/src/components/DownloadAll.tsx +++ b/src/components/DownloadAll.tsx @@ -1,23 +1,43 @@ -import { DecryptedAudioFile, selectFiles } from '~/features/file-listing/fileListingSlice'; +import { DecryptedAudioFile, ProcessState, selectFiles } from '~/features/file-listing/fileListingSlice'; import { FaDownload } from 'react-icons/fa'; import { useAppSelector } from '~/hooks'; import { toast } from 'react-toastify'; export function DownloadAll() { const files = useAppSelector(selectFiles); - const filesLength = Object.keys(files).length; const onClickDownloadAll = async () => { + if (Object.keys(files).length === 0) { + toast.warning('未添加文件'); + return; + } + + //判断所有文件是否处理完成 + const allComplete = Object.values(files).every((file) => file.state !== ProcessState.PROCESSING); + if (!allComplete) { + toast.warning('请等待所有文件解密完成'); + return; + } + + //过滤处理失败的文件 + const completeFiles = Object.values(files).filter((file) => file.state === ProcessState.COMPLETE); + const filesLength = Object.keys(completeFiles).length; + + //开始下载 let dir: FileSystemDirectoryHandle | undefined; let success = 0; try { - dir = await window.showDirectoryPicker(); + dir = await window.showDirectoryPicker({ mode: 'readwrite' }); } catch (e) { console.error(e); if (e instanceof Error && e.name === 'AbortError') { return; } } - for (const [_, file] of Object.entries(files)) { + toast.warning('开始下载,请稍候'); + for (const [_, file] of Object.entries(completeFiles)) { + if (file.state !== ProcessState.COMPLETE) { + return; + } try { if (dir) { await DownloadNew(dir, file); @@ -33,7 +53,7 @@ export function DownloadAll() { if (success === filesLength) { toast.success(`成功下载: ${success}/${filesLength}首`); } else { - toast.error(`成功下载: ${success}/${filesLength}首`); + toast.warning(`成功下载: ${success}/${filesLength}首`); } };