File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -49,10 +49,19 @@ export const getOtherSource = async(musicInfo: LX.Music.MusicInfo | LX.Download.
4949 }
5050 if ( getOtherSourcePromises . has ( key ) ) return getOtherSourcePromises . get ( key )
5151
52- const promise = musicSdk . findMusic ( searchMusicInfo ) . then ( ( otherSource ) => {
53- const sources : LX . Music . MusicInfoOnline [ ] = otherSource . map ( toNewMusicInfo ) as LX . Music . MusicInfoOnline [ ]
54- if ( sources . length ) void saveOtherSourceFromStore ( musicInfo . id , sources )
55- return sources
52+ const promise = new Promise < LX . Music . MusicInfoOnline [ ] > ( ( resolve , reject ) => {
53+ let timeout : null | NodeJS . Timeout = setTimeout ( ( ) => {
54+ timeout = null
55+ reject ( new Error ( 'find music timeout' ) )
56+ } , 20_000 )
57+ musicSdk . findMusic ( searchMusicInfo ) . then ( ( otherSource ) => {
58+ resolve ( otherSource . map ( toNewMusicInfo ) as LX . Music . MusicInfoOnline [ ] )
59+ } ) . catch ( reject ) . finally ( ( ) => {
60+ if ( timeout ) clearTimeout ( timeout )
61+ } )
62+ } ) . then ( ( otherSource ) => {
63+ if ( otherSource . length ) void saveOtherSourceFromStore ( musicInfo . id , otherSource )
64+ return otherSource
5665 } ) . finally ( ( ) => {
5766 if ( getOtherSourcePromises . has ( key ) ) getOtherSourcePromises . delete ( key )
5867 } )
You can’t perform that action at this time.
0 commit comments