From 41c46a664cfbb0a0557c94266956a242225d1cb9 Mon Sep 17 00:00:00 2001 From: Arne van Iterson Date: Thu, 26 Sep 2019 22:04:41 +0200 Subject: [PATCH] Removed unnecessary code & added element types --- routes/index.js | 39 ++++++++------------------------------- 1 file changed, 8 insertions(+), 31 deletions(-) diff --git a/routes/index.js b/routes/index.js index feb4084..fa093a7 100644 --- a/routes/index.js +++ b/routes/index.js @@ -49,11 +49,15 @@ function dbGet(type, id) { if (id === 'all') { result = db[type]; + result.forEach(element => { + element.type = type; + }); } else { id = parseInt(id); db[type].forEach(element => { if (id == element.id) { result = element; + result.type = type; } }); } @@ -74,39 +78,11 @@ router.get('/get/:type/:id', (req, res, _next) => { const arg = id.split(","); resultArray = []; - // TODO - // OK, for some reason this script works absolutely fine when run the fist time, - // However, if you run any other get url or refresh the page it will either throw a circulation error or return a bunch of null values - // I have no idea what is causing this but i am absolutely fucking done with it right now - // If you read this and you know how to fix it, please change it - // For each array in argument, make object in resultArray for (let index = 0; index < arg.length; index++) { resultArray[index] = dbGet(type, arg[index]); - - // Add song info if id is given - if (typeof resultArray[index].song !== 'undefined') { - for (let song = 0; song < resultArray[index].song.length; song++) { - resultArray[index].song[song] = dbGet('song', resultArray[index].song[song]); - } - } - - // Add artist info if id is given - if (typeof resultArray[index].artist !== 'undefined') { - for (let artist = 0; artist < resultArray[index].artist.length; artist++) { - resultArray[index].artist[artist] = dbGet('artist', resultArray[index].artist[artist]); - } - } - - - // Add album info if id is given - if (typeof resultArray[index].album !== 'undefined') { - for (let album = 0; album < resultArray[index].album.length; album++) { - resultArray[index].album[album] = dbGet('album', resultArray[index].album[album]); - } - } - } + // Print result res.json({ result: resultArray }); } @@ -186,13 +162,14 @@ router.get('/search/:query', (req, res, _next) => { }); }); + router.use(urlParse.urlencoded({extended : true})); // Analyse route to scan .mp3 ID3 tags router.get('/analyse/*', (req, res, _next) => { - let file = '/' + req.params[0]; + let file = req.params[0]; if (fs.existsSync(file)) { var result = id3.read(file); - if (result.image.imageBuffer) { + if (typeof result.image.imageBuffer !== 'undefined') { result.image.base64 = result.image.imageBuffer.toString('base64'); } } else {