@@ -21,9 +21,6 @@ const effects = new Set([
2121] ) ;
2222
2323async function updateFile ( path , data ) {
24- // Create blank if not exists
25- await fs . writeFile ( path , Array . isArray ( data ) ? [ ] : { } , { flag : 'wx' } ) ;
26-
2724 // Load existing
2825 const file = await fs . readFile ( path ) ;
2926 const existing = JSON . parse ( file . toString ( ) ) ;
@@ -45,23 +42,25 @@ async function download(url, file) {
4542 try {
4643 const image = await fetch ( url ) ;
4744 await fs . writeFile ( file , image . body ) ;
48- } catch {
49- console . error ( 'Failed to save' , basename ( file ) ) ;
45+ } catch ( e ) {
46+ console . error ( 'Failed to save' , basename ( file ) , e . message || e ) ;
5047 }
5148}
5249
5350async function downloadAvatars ( images ) {
5451 const path = join ( base , 'images' , 'avatars' ) ;
55- for ( const name in images ) {
52+ await fs . mkdir ( path , { recursive : true } ) ;
53+ for ( const name of images ) {
5654 const url = `https://undercards.net/images/cards/${ name } .png` ;
5755 await download ( url , resolve ( path , `${ name } .png` ) ) ;
5856 }
5957}
6058
6159async function downloadEffects ( ) {
6260 const path = join ( base , 'images' , 'effects' ) ;
61+ await fs . mkdir ( path , { recursive : true } ) ;
6362 const values = effects . values ( ) ;
64- for ( const effect in values ) {
63+ for ( const effect of values ) {
6564 const url = `https://undercards.net/images/powers/${ effect } .png` ;
6665 await download ( url , resolve ( path , `${ effect } .png` ) ) ;
6766 }
@@ -76,7 +75,7 @@ fetch('https://undercards.net/AllCards')
7675 } ) ) )
7776 . then ( ( avatars ) => Promise . all ( [
7877 updateFile ( resolve ( base , 'data' , 'avatars.json' ) , avatars ) ,
79- updateFile ( resolve ( base , 'data' , 'effects .json' ) , effects . values ( ) ) ,
78+ updateFile ( resolve ( base , 'data' , 'status .json' ) , effects . values ( ) ) ,
8079 downloadAvatars ( Object . values ( avatars ) ) ,
8180 downloadEffects ( ) ,
8281 ] ) ) ;
0 commit comments