From a5d0ec29a189d520d0d4d819886ac8a93e62feed Mon Sep 17 00:00:00 2001 From: awalol Date: Mon, 16 Jun 2025 00:56:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=87=E4=BB=B6=E5=A4=B9?= =?UTF-8?q?=E9=80=89=E5=8F=96=E5=8F=96=E6=B6=88=E5=88=A4=E6=96=AD=20?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=20toast=20=E8=BF=9B=E8=A1=8C=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=20=E4=BD=BF=E7=94=A8=20react-icons=20=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E4=B8=8B=E8=BD=BD=E5=9B=BE=E6=A0=87=20=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=20pipeTo=20=E6=96=B9=E6=B3=95=E5=86=99=E5=87=BA?= =?UTF-8?q?=E5=88=B0=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/DownloadAll.tsx | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/components/DownloadAll.tsx b/src/components/DownloadAll.tsx index dad0f0f..5975033 100644 --- a/src/components/DownloadAll.tsx +++ b/src/components/DownloadAll.tsx @@ -1,5 +1,7 @@ import { DecryptedAudioFile, 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); @@ -11,6 +13,9 @@ export function DownloadAll() { dir = await window.showDirectoryPicker(); } catch (e) { console.error(e); + if (e instanceof Error && e.name === 'AbortError') { + return; + } } for (const [_, file] of Object.entries(files)) { try { @@ -21,10 +26,15 @@ export function DownloadAll() { } success++; } catch (e) { - console.error('下载失败: ' + file.fileName, e); + console.error(`下载失败: ${file.fileName}`, e); + toast.error(`出现错误: ${e}`); } } - alert('下载成功: ' + success + ',下载失败: ' + (filesLength - success)); + if (success === filesLength) { + toast.success(`成功下载: ${success}/${filesLength}首`); + } else { + toast.error(`成功下载: ${success}/${filesLength}首`); + } }; return ( @@ -34,21 +44,15 @@ export function DownloadAll() { onClick={onClickDownloadAll} title="下载全部" > - - - - + ); } async function DownloadNew(dir: FileSystemDirectoryHandle, file: DecryptedAudioFile) { - const response = await fetch(file.decrypted); - const blob = await response.blob(); const fileHandle = await dir.getFileHandle(file.cleanName + '.' + file.ext, { create: true }); const writable = await fileHandle.createWritable(); - await writable.write(blob); - await writable.close(); + await fetch(file.decrypted).then((res) => res.body?.pipeTo(writable)); } async function DownloadOld(file: DecryptedAudioFile) {