mirror of
https://github.com/janishutz/MusicPlayerV2.git
synced 2025-11-25 21:14:22 +00:00
progress on dir crawling
This commit is contained in:
@@ -16,7 +16,29 @@ app.get( '/', ( request, response ) => {
|
||||
|
||||
|
||||
app.get( '/openSongs', ( req, res ) => {
|
||||
res.send( { 'data': dialog.showOpenDialogSync( { properties: [ 'openDirectory' ], title: 'Open music library folder' } ) } );
|
||||
res.send( '{ "data": [ "/home/janis/Music/KB2022" ] }' )
|
||||
// res.send( { 'data': dialog.showOpenDialogSync( { properties: [ 'openDirectory' ], title: 'Open music library folder' } ) } );
|
||||
} );
|
||||
|
||||
app.get( '/indexDirs', ( req, res ) => {
|
||||
if ( req.query.dir ) {
|
||||
fs.readdir( req.query.dir, { encoding: 'utf-8' }, ( err, dat ) => {
|
||||
if ( err ) res.status( 500 ).send( 'err' );
|
||||
res.send( dat );
|
||||
} );
|
||||
} else {
|
||||
res.status( 400 ).send( 'ERR_REQ_INCOMPLETE' );
|
||||
}
|
||||
} );
|
||||
|
||||
app.get( '/getSongDetails', ( req, res ) => {
|
||||
if ( req.query.filename ) {
|
||||
fs.readFile( req.query.filename, ( err, data ) => {
|
||||
res.send( '' + data );
|
||||
} );
|
||||
} else {
|
||||
res.status( 400 ).send( 'ERR_REQ_INCOMPLETE' );
|
||||
}
|
||||
} );
|
||||
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
hasLoadedSongs: false,
|
||||
songQueue: [],
|
||||
loadedDirs: [],
|
||||
allowedFiletypes: [ '.mp3', '.wav' ]
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
@@ -49,9 +50,26 @@
|
||||
res.json().then( json => {
|
||||
this.hasLoadedSongs = true;
|
||||
this.loadedDirs = json.data;
|
||||
this.indexFiles();
|
||||
} );
|
||||
}
|
||||
} );
|
||||
},
|
||||
indexFiles () {
|
||||
for ( let dir in this.loadedDirs ) {
|
||||
fetch( 'http://localhost:8081/indexDirs?dir=' + this.loadedDirs[ dir ] ).then( res => {
|
||||
if ( res.status === 200 ) {
|
||||
res.json().then( json => {
|
||||
for ( let file in json ) {
|
||||
const fileType = json[ file ].slice( json[ file ].indexOf( '.' ), json[ file ].length );
|
||||
if ( this.allowedFiletypes.includes( fileType ) ) {
|
||||
this.songQueue.push( json[ file ] );
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user