some more progress

This commit is contained in:
janis
2023-11-16 16:16:47 +01:00
parent 5a133e3f12
commit 142a835048
2 changed files with 63 additions and 2 deletions

View File

@@ -8,6 +8,28 @@
*/
const path = require( 'path' );
const dialog = require( 'electron' ).dialog;
const analyzeFile = ( filepath ) => {
return new Promise( ( resolve, reject ) => {
if ( filepath.includes( '.csv' ) ) {
// This will assume that line #1 will be song #1 in the file list
// (when sorted by name)
let results = {};
let pos = 0;
fs.createReadStream( filepath )
.pipe( csv() )
.on( 'data', ( data ) => {
results[ pos ] = data;
pos += 1;
} ).on( 'end', () => {
resolve( results );
} );
} else if ( filepath.includes( '.json' ) ) {
resolve( JSON.parse( fs.readFileSync( filepath ) ) );
}
} );
}
module.exports = ( app ) => {
app.get( '/apple-music', ( req, res ) => {
@@ -29,4 +51,22 @@ module.exports = ( app ) => {
app.get( '/logo.png', ( req, res ) => {
res.sendFile( path.join( __dirname + '/client/logo.png' ) );
} );
app.get( '/apple-music/getAdditionalData', ( req, res ) => {
const filepath = dialog.showOpenDialogSync( {
properties: [ 'openFile' ],
title: 'Open file with additional data on the songs',
filters: [
{
name: 'CSV', extensions: [ '.csv' ],
name: 'JSON', extensions: [ '.json' ]
}
]
} );
analyzeFile( filepath ).then( analyzedFile => {
res.send( analyzeFile );
} ).catch( err => {
res.status( 500 ).send( 'no csv / json file' );
} )
} );
}