File tree Expand file tree Collapse file tree 1 file changed +14
-8
lines changed Expand file tree Collapse file tree 1 file changed +14
-8
lines changed Original file line number Diff line number Diff line change @@ -36,21 +36,27 @@ export async function parseAndSaveSongs(
36
36
store . delete ( 'songs' ) ;
37
37
38
38
glob ( `${ result . filePaths [ 0 ] } /**/notes.mid` , { } , ( err , files ) => {
39
+ const supportedImageExtensions = [ 'png' , 'jpg' , 'jpeg' ] ;
40
+
39
41
const songList = files
40
42
. map ( ( file ) => path . join ( path . dirname ( file ) , 'song.ini' ) )
41
43
. filter ( ( file ) => fs . existsSync ( file ) )
42
44
. map ( ( file ) => ( {
43
45
info : ini . parse ( fs . readFileSync ( file , 'utf-8' ) ) ,
44
46
dir : path . dirname ( file ) ,
45
47
} ) )
46
- . map ( ( { info, dir } ) => ( {
47
- id : randomUUID ( ) ,
48
- dir,
49
- albumCover : fs . existsSync ( path . join ( dir , 'album.png' ) )
50
- ? `gh:///${ path . join ( dir , 'album.png' ) } `
51
- : null ,
52
- ...( info . song ?? info . Song ?? info ) ,
53
- } ) ) ;
48
+ . map ( ( { info, dir } ) => {
49
+ const albumCoverPath = supportedImageExtensions
50
+ . map ( ext => path . join ( dir , `album.${ ext } ` ) )
51
+ . find ( p => fs . existsSync ( p ) ) ;
52
+
53
+ return {
54
+ id : randomUUID ( ) ,
55
+ dir,
56
+ albumCover : albumCoverPath ? `gh:///${ albumCoverPath } ` : null ,
57
+ ...( info . song ?? info . Song ?? info ) ,
58
+ } ;
59
+ } ) ;
54
60
55
61
const songs = songList . reduce ( ( acc , song ) => {
56
62
acc [ song . id ] = song ;
You can’t perform that action at this time.
0 commit comments