From 656dbc5fe4e2f7cd96ad8684022112ade3173bfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8C=AB=E5=A4=B4=E7=8C=AB?= Date: Tue, 30 Aug 2022 00:08:55 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8E=BB=E9=99=A4=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E7=9A=84=E5=86=97=E4=BD=99=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/downloadManager.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/common/downloadManager.ts b/src/common/downloadManager.ts index 71b84b4..0aeb3fc 100644 --- a/src/common/downloadManager.ts +++ b/src/common/downloadManager.ts @@ -59,19 +59,25 @@ async function setupDownload() { return; } downloadedData = (await getStorage('download-music')) ?? {}; + const newDownloadedData: Record = {}; const downloads = await readDir(pathConst.downloadPath); downloadedMusic = []; + for (let i = 0; i < downloads.length; ++i) { const data = parseFilename(downloads[i].name); if (data) { - const mi = downloadedData[`${data.platform}${data.id}`] ?? {...data}; + const key = `${data.platform}${data.id}`; + const mi = downloadedData[key] ?? {...data}; mi[internalKey] = { localPath: downloads[i].path, }; - mi && downloadedMusic.push(mi); + downloadedMusic.push(mi); + newDownloadedData[key] = mi; } } downloadedStateMapper.notify(); + // 去掉冗余数据 + setStorage('download-music', newDownloadedData); } /** 从队列取出下一个要下载的 */ @@ -212,7 +218,7 @@ const DownloadManager = { isDownloaded, useIsDownloaded, getDownloaded, - removeDownloaded + removeDownloaded, }; export default DownloadManager;