From 94dccae48adf7474c33174941f00a7f363bc7785 Mon Sep 17 00:00:00 2001 From: lyswhut Date: Tue, 12 Sep 2023 12:52:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8D=A2=E6=BA=90=E8=B6=85?= =?UTF-8?q?=E6=97=B6=E5=AE=9A=E6=97=B6=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/core/music/utils.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/renderer/core/music/utils.ts b/src/renderer/core/music/utils.ts index e678ec31..52c446cf 100644 --- a/src/renderer/core/music/utils.ts +++ b/src/renderer/core/music/utils.ts @@ -49,10 +49,19 @@ export const getOtherSource = async(musicInfo: LX.Music.MusicInfo | LX.Download. } if (getOtherSourcePromises.has(key)) return getOtherSourcePromises.get(key) - const promise = musicSdk.findMusic(searchMusicInfo).then((otherSource) => { - const sources: LX.Music.MusicInfoOnline[] = otherSource.map(toNewMusicInfo) as LX.Music.MusicInfoOnline[] - if (sources.length) void saveOtherSourceFromStore(musicInfo.id, sources) - return sources + const promise = new Promise((resolve, reject) => { + let timeout: null | NodeJS.Timeout = setTimeout(() => { + timeout = null + reject(new Error('find music timeout')) + }, 20_000) + musicSdk.findMusic(searchMusicInfo).then((otherSource) => { + resolve(otherSource.map(toNewMusicInfo) as LX.Music.MusicInfoOnline[]) + }).catch(reject).finally(() => { + if (timeout) clearTimeout(timeout) + }) + }).then((otherSource) => { + if (otherSource.length) void saveOtherSourceFromStore(musicInfo.id, otherSource) + return otherSource }).finally(() => { if (getOtherSourcePromises.has(key)) getOtherSourcePromises.delete(key) })