progress on dir crawling

This commit is contained in:
janis
2023-10-19 13:53:45 +02:00
parent 801a646a4d
commit 435bbad2e7
3 changed files with 279 additions and 220 deletions

View File

@@ -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' );
}
} );

View File

@@ -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 ] );
}
}
} );
}
} );
}
}
}
}