From e14b0364d582f3bb3a527f8be7e156d688995940 Mon Sep 17 00:00:00 2001 From: stickyPiston Date: Wed, 18 Sep 2019 13:52:34 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=99=88=20Added=20music=20folder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It gave some annoying errors... hmpf... --- .gitignore | 3 +-- music/.gitkeep | 0 2 files changed, 1 insertion(+), 2 deletions(-) create mode 100644 music/.gitkeep diff --git a/.gitignore b/.gitignore index b0d9e98..10ceee8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ node_modules/ -bin/ffmpeg -music/ \ No newline at end of file +bin/ffmpeg \ No newline at end of file diff --git a/music/.gitkeep b/music/.gitkeep new file mode 100644 index 0000000..e69de29 From af97ee82d78e27fa3ea6db560ff01f68523f3fe6 Mon Sep 17 00:00:00 2001 From: stickyPiston Date: Thu, 19 Sep 2019 08:06:21 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20some=20minor=20bugs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some directories were pointed wrong. --- routes/index.js | 35 ++++++++++++++++++++--------------- views/index.pug | 2 +- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/routes/index.js b/routes/index.js index 7971670..fafbf67 100644 --- a/routes/index.js +++ b/routes/index.js @@ -36,23 +36,27 @@ router.get('/get/:type/:id', (req, res, _next) => { let db = {}; if (type === 'song') { - db = require(rootdir + '/songs.json'); + db = require(rootdir + 'database/songs.json'); } else if (type === 'album') { - db = require(rootdir + '/albums.json'); + db = require(rootdir + "database/albums.json"); } else if (type === 'artist') { - db = require(rootdir + '/artists.json'); + db = require(rootdir + "database/artists.json"); } - const arg = id.split(','); - - if (arg.length > 1) { - let result = []; - arg.forEach(element => { - result.push(db[Number(element)]); - }); - res.json({ result: result }); + if (id === 'all') { + res.json({result: db}) } else { - res.json({ result: db[id] }); + const arg = id.split(","); + + if (arg.length > 1) { + let result = []; + arg.forEach(element => { + result.push(db[Number(element)]); + }); + res.json({ result: result }); + } else { + res.json({ result: db[id] }); + } } }); @@ -60,7 +64,7 @@ router.get('/get/:type/:id', (req, res, _next) => { router.get('/play/:track', (req, res, _next) => { var key = req.params.track; - var music = rootdir + "/music/" + key + ".mp3"; + var music = rootdir + "music/" + key + ".mp3"; var stat = fs.statSync(music); range = req.headers.range; @@ -110,13 +114,14 @@ router.get('/search/:query', (req, res, _next) => { const query = req.params.query; let result = []; - fs.readdir(rootdir + '/database/', (err, files) => { + fs.readdir(rootdir + 'database/', (err, files) => { files.forEach(file => { - const content = require(rootdir + '/database/' + file); + const content = require(rootdir + 'database/' + file); content.forEach(element => { if (element.name.match(query)) { + element.foundIn = file; result.push(element); } }); diff --git a/views/index.pug b/views/index.pug index a79df80..d7ef24f 100644 --- a/views/index.pug +++ b/views/index.pug @@ -3,7 +3,7 @@ extends layout block content h1= title p Welcome to #{title} - form(action="/download" method="get") + form(action="download" method="get") label(for="url") input(name="url" type="text") input(type="submit")