mirror of
https://github.com/janishutz/MusicPlayerV2.git
synced 2025-11-25 13:04:23 +00:00
backend
This commit is contained in:
@@ -21,8 +21,8 @@ app.use( session( {
|
||||
|
||||
|
||||
// TODO: Import from config
|
||||
const remoteURL = 'https://music.janishutz.com';
|
||||
const hasConnected = false;
|
||||
const remoteURL = 'http://localhost:3000';
|
||||
let hasConnected = false;
|
||||
|
||||
const connect = () => {
|
||||
if ( authKey !== '' ) {
|
||||
@@ -69,9 +69,9 @@ app.get( '/', ( request, response ) => {
|
||||
} );
|
||||
|
||||
app.get( '/openSongs', ( req, res ) => {
|
||||
// res.send( '{ "data": [ "/home/janis/Music/KB2022" ] }' );
|
||||
res.send( '{ "data": [ "/home/janis/Music/KB2022" ] }' );
|
||||
// res.send( '{ "data": [ "/mnt/storage/SORTED/Music/audio/KB2022" ] }' );
|
||||
res.send( { 'data': dialog.showOpenDialogSync( { properties: [ 'openDirectory' ], title: 'Open music library folder' } ) } );
|
||||
// res.send( { 'data': dialog.showOpenDialogSync( { properties: [ 'openDirectory' ], title: 'Open music library folder' } ) } );
|
||||
} );
|
||||
|
||||
app.get( '/showcase.js', ( req, res ) => {
|
||||
@@ -122,15 +122,24 @@ const sendUpdate = ( update ) => {
|
||||
for ( let client in connectedClients ) {
|
||||
connectedClients[ client ].write( 'data: ' + JSON.stringify( { 'type': update, 'data': currentDetails[ update ] } ) + '\n\n' );
|
||||
}
|
||||
// TODO: Check if connected and if not, try to authenticate with data from authKey file
|
||||
// TODO: reduce request count by bundling and sending more in one go to reduce load
|
||||
|
||||
// Check if connected and if not, try to authenticate with data from authKey file
|
||||
|
||||
if ( hasConnected ) {
|
||||
axios.post( remoteURL + '/statusUpdate', { 'data': 'hello' } ).then( res => {
|
||||
console.log( res );
|
||||
if ( update === 'pos' ) {
|
||||
return;
|
||||
} else if ( update === 'playingSong' ) {
|
||||
currentDetails[ update ][ 'startTime' ] === new Date().getTime();
|
||||
}
|
||||
axios.post( remoteURL + '/statusUpdate', { 'type': update, 'data': currentDetails[ update ], 'authKey': authKey } ).then( res => {
|
||||
if ( res.status !== 200 ) {
|
||||
console.log( res );
|
||||
}
|
||||
} ).catch( err => {
|
||||
console.error( err );
|
||||
} );
|
||||
} else {
|
||||
connect();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -285,8 +285,12 @@
|
||||
fetch( 'http://localhost:8081/openSongs' ).then( res => {
|
||||
if ( res.status === 200 ) {
|
||||
res.json().then( json => {
|
||||
this.loadedDirs = json.data;
|
||||
this.indexFiles();
|
||||
if ( Object.keys( json ).length > 0 ) {
|
||||
this.loadedDirs = json.data;
|
||||
this.indexFiles();
|
||||
} else {
|
||||
this.isLoadingSongs = false;
|
||||
}
|
||||
} );
|
||||
}
|
||||
} );
|
||||
|
||||
@@ -363,8 +363,6 @@ export default {
|
||||
} else if ( e.key === 'ArrowLeft' ) {
|
||||
e.preventDefault();
|
||||
this.control( 'previous' );
|
||||
} else {
|
||||
console.log( e.key );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
1
frontend/src/config/authKey.txt
Normal file
1
frontend/src/config/authKey.txt
Normal file
@@ -0,0 +1 @@
|
||||
gaöwovwef89voawö8p9 odövefw8öoaewpf89wec
|
||||
Reference in New Issue
Block a user