File tree Expand file tree Collapse file tree 2 files changed +36
-4
lines changed
Expand file tree Collapse file tree 2 files changed +36
-4
lines changed Original file line number Diff line number Diff line change 1+
2+ export function preloadImage ( src : string , timeout : number = 10000 ) : Promise < boolean > {
3+ return new Promise ( ( resolve ) => {
4+ const img = document . createElement ( "img" ) ;
5+ let complete = false ;
6+
7+ img . style . position = "absolute" ;
8+ img . style . top = "10000%" ;
9+ img . src = src ;
10+
11+ function done ( result : boolean ) {
12+ if ( complete )
13+ return ;
14+
15+ complete = true ;
16+ img . remove ( ) ;
17+ resolve ( result ) ;
18+ }
19+
20+ img . onload = ( ) => done ( true ) ;
21+ img . onerror = ( ) => done ( false ) ;
22+
23+ setTimeout ( ( ) => done ( false ) , timeout ) ;
24+ } ) ;
25+ }
Original file line number Diff line number Diff line change 77 import { SongAPI } from " $lib/api/api" ;
88 import ProgressBar from " $lib/comp/ProgressBar.svelte" ;
99 import { wait } from " $lib/util" ;
10+ import { preloadImage } from " $lib/util/dom" ;
1011
1112 const api = new SongAPI ();
1213
2728
2829 if (stats ) {
2930 const songs = stats .data .songs .slice (0 , config .songRankCount );
30- progressMax = songs .length * 2 ;
31+ progressMax = songs .length * 3 ;
3132
3233 for (let i = 0 ; i < songs .length ; i ++ ) {
33- const song = songs [i ];
34+ const songStat = songs [i ];
3435
35- const artist = await api .queryArtistByName (song .artist );
36+ const artist = await api .queryArtistByName (songStat .artist );
3637 progress ++ ;
3738
38- await api .querySongByName (song .title , artist ?.id );
39+ const song = await api .querySongByName (songStat .title , artist ?.id );
40+ progress ++ ;
41+
42+ if (song ?.coverArt ) {
43+ await preloadImage (song .coverArt , 2000 );
44+ }
45+
3946 progress ++ ;
4047
4148 // Account for rate limit
You can’t perform that action at this time.
0 commit comments