From 7879fb52b388c9a5741a6c0097544d77ca05844c Mon Sep 17 00:00:00 2001 From: IrosTheBeggar Date: Fri, 3 Mar 2017 23:21:40 -0500 Subject: [PATCH] Cleanup and doc search and download endpoints --- docs/API.md | 3 ++ docs/API/db_search.md | 37 +++++++++++++++++ docs/API/download.md | 25 ++++++++++++ docs/cli_arguments.md | 0 docs/docker.md | 17 ++++++++ docs/install.md | 50 +++++++++++++++++++++++ modules/db-read/database-public-beets.js | 2 +- modules/db-read/database-public-sqlite.js | 3 +- modules/download.js | 4 +- public/js/mstream.js | 4 +- 10 files changed, 138 insertions(+), 7 deletions(-) create mode 100644 docs/API/db_search.md create mode 100644 docs/API/download.md create mode 100644 docs/cli_arguments.md create mode 100644 docs/docker.md create mode 100644 docs/install.md diff --git a/docs/API.md b/docs/API.md index 8bf6878..56950de 100644 --- a/docs/API.md +++ b/docs/API.md @@ -62,6 +62,8 @@ http://yourserver.com/vPath/filepath/song.mp3?token=XXXXXXXX #### Database Read (Albums/Artists/Etc) +[/db/search](API/db_search.md) + [/db/albums](API/db_albums.md) [/db/artists](API/db_artists.md) @@ -71,6 +73,7 @@ http://yourserver.com/vPath/filepath/song.mp3?token=XXXXXXXX [/jukebox/push-to-client.md](API/jukebox_push-to-client.md) #### Download +[/download](API/download.md) #### Shared diff --git a/docs/API/db_search.md b/docs/API/db_search.md new file mode 100644 index 0000000..6f8631b --- /dev/null +++ b/docs/API/db_search.md @@ -0,0 +1,37 @@ +**Search DB ** +---- + Retrieves albums and artists that much a given string + +* **URL** + + /db/search + +* **Method:** + + `POST` + +* **JSON Params** + + **Required:** + + `search` - String that will be searched for + +* **JSON Example** + + ``` + { + 'search': 'The Offsp' + } + ``` + +* **Success Response:** + + * **Code:** 200
+ **Content:** + + ``` + { + "albums":[album1, album2], + "artists":[artist1, artist2, artist3] + } + ``` diff --git a/docs/API/download.md b/docs/API/download.md new file mode 100644 index 0000000..c485366 --- /dev/null +++ b/docs/API/download.md @@ -0,0 +1,25 @@ +**Download Files** +---- + Will zip files up and them download the zip file + +* **URL** + + /download + +* **Method:** + + `POST` + +* **Params** + + The download endpoint gets the list of files to download through the POST param `fileArray`. The reason for this is due to the finicky way some browsers handle downloads. + +* **JSON Example** + + ``` + ['path/to/file1.mp3', path/to/file2.flac] + ``` + +* **Success Response:** + + Will download a zip file diff --git a/docs/cli_arguments.md b/docs/cli_arguments.md new file mode 100644 index 0000000..e69de29 diff --git a/docs/docker.md b/docs/docker.md new file mode 100644 index 0000000..f232510 --- /dev/null +++ b/docs/docker.md @@ -0,0 +1,17 @@ +#### Using Docker + +Download the Dockerfile, or clone the repository, then run the following +commands: + +```shell +docker build -t local/mstream . + +docker run --rm -v /path/to/my/music:/music local/mstream +``` + +The ENTRYPOINT is `mstream`, so you can use the same option as if using the +default installation. + +```shell +docker run --rm -v /path/to/my/music:/music local/mstream -l -u username -x password +``` diff --git a/docs/install.md b/docs/install.md new file mode 100644 index 0000000..c9e1f88 --- /dev/null +++ b/docs/install.md @@ -0,0 +1,50 @@ +## Install on Ubuntu + +**Dependencies** + +mStream has the following dependencies: + +* NodeJS and NPM +* Python 2 +* GCC and G++ +* node-gyp + +**Install NodeJS** + +```shell +curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash - +sudo apt-get update +sudo apt-get install -y nodejs +``` + +**Install GCC and node-gyp** + +```shell +sudo apt-get install -y build-essential +sudo npm install -g node-gyp +``` + +**Install mStream** + +Install through NPM + +```shell +sudo npm install -g mstream + +cd /path/to/your/music +mstream +``` + +Or Install through Git + +```shell +git clone https://github.com/IrosTheBeggar/mStream.git + +cd mStream + +npm install + +sudo npm link +``` + +Test it by running `mstream` in the terminal. Make sure it's working by checking out http://localhost:3000/ diff --git a/modules/db-read/database-public-beets.js b/modules/db-read/database-public-beets.js index c1cb5fe..c1f07d4 100644 --- a/modules/db-read/database-public-beets.js +++ b/modules/db-read/database-public-beets.js @@ -136,7 +136,7 @@ exports.setup = function(mstream, dbSettings){ mstream.post('/db/search', function(req, res){ - var searchTerm = "%" + req.body.search + "%" ; + var searchTerm = "%" + req.parsedJSON.search + "%" ; var returnThis = {"albums":[], "artists":[]}; diff --git a/modules/db-read/database-public-sqlite.js b/modules/db-read/database-public-sqlite.js index f32b975..9033fc3 100644 --- a/modules/db-read/database-public-sqlite.js +++ b/modules/db-read/database-public-sqlite.js @@ -132,14 +132,13 @@ exports.setup = function(mstream, dbSettings){ // Delete playlist from DB db.run("DELETE FROM mstream_playlists WHERE playlist_name = ? AND user = ?;", [playlistname, req.user.username], function(){ res.send('{success: true}'); - }); } }); mstream.post('/db/search', function(req, res){ - var searchTerm = "%" + req.body.search + "%" ; + var searchTerm = "%" + req.parsedJSON.search + "%" ; var returnThis = {"albums":[], "artists":[]}; diff --git a/modules/download.js b/modules/download.js index fb308cf..6d030da 100644 --- a/modules/download.js +++ b/modules/download.js @@ -1,7 +1,7 @@ exports.setup = function(mstream, program){ const archiver = require('archiver'); // Zip Compression const fe = require('path'); - + // Download a zip file of music mstream.post('/download', function (req, res){ @@ -38,7 +38,7 @@ exports.setup = function(mstream, program){ var fileString = fileArray[i]; // TODO: Add file by ataching user's musicdir to the relative directory supplied - archive.file(fe.normalize( fileString), { name: fe.basename(fileString) }); + archive.file(fe.join( req.user.musicDir, fileString), { name: fe.basename(fileString) }); } archive.finalize(); diff --git a/public/js/mstream.js b/public/js/mstream.js index be6a44c..3315efd 100755 --- a/public/js/mstream.js +++ b/public/js/mstream.js @@ -1102,9 +1102,9 @@ $("#filelist").on('click', '.playlistz', function() { if($(this).val().length>1){ var request = $.ajax({ - url: "db/search", + url: "/db/search", type: "POST", - data: { search : $(this).val() }, + data: { json: JSON.stringify({ search: $(this).val() })}, }); request.done(function( msg ) {