diff --git a/modules/db-read/database-public-loki.js b/modules/db-read/database-public-loki.js index b765482..c3ccb7d 100644 --- a/modules/db-read/database-public-loki.js +++ b/modules/db-read/database-public-loki.js @@ -577,13 +577,16 @@ exports.setup = function (mstream, program) { }); mstream.post('/db/search', (req, res) => { + if (!req.body.search) { + res.status(500).json({ error: 'Bad input data' }); + } // Get user inputs - const artists = searchByX(req, 'artist'); - const albums = searchByX(req, 'album'); - const files = searchByX(req, 'filepath'); - // const title = searchByX(req, 'title', 'filepath'); + const artists = req.body.noArtists === false ? [] : searchByX(req, 'artist'); + const albums = req.body.noAlbums === false ? [] : searchByX(req, 'album'); + const files = req.body.noFiles === false ? [] : searchByX(req, 'filepath'); + const title = req.body.noTitles === false ? [] : searchByX(req, 'title', 'filepath'); - res.json({artists, albums, files }); + res.json({artists, albums, files, title }); }); function searchByX(req, searchCol, resCol) { @@ -615,9 +618,21 @@ exports.setup = function (mstream, program) { const store = {}; for (let row of results) { if (!store[row[resCol]]) { + let name = row[resCol]; + let filepath = false; + + if (searchCol === 'filepath') { + name = fe.join(row.vpath, row[resCol]).replace(/\\/g, '/'); + filepath = fe.join(row.vpath, row[resCol]).replace(/\\/g, '/'); + } else if (searchCol === 'title') { + name = `${row.artist} - ${row.title}`; + filepath = fe.join(row.vpath, row[resCol]).replace(/\\/g, '/'); + } + returnThis.push({ - name: row[resCol], - album_art_file: row.aaFile ? row.aaFile : null + name: name, + album_art_file: row.aaFile ? row.aaFile : null, + filepath }); store[row[resCol]] = true; } diff --git a/public/js/api2.js b/public/js/api2.js index 84885f3..d8d19e8 100644 --- a/public/js/api2.js +++ b/public/js/api2.js @@ -81,8 +81,8 @@ var MSTREAMAPI = (function () { makePOSTRequest('/playlist/add-song', { playlist: playlist, song: song }, callback); } - mstreamModule.search = function (searchTerm, callback) { - makePOSTRequest('/db/search', { search: searchTerm }, callback); + mstreamModule.search = function (postObject, callback) { + makePOSTRequest('/db/search', postObject, callback); } mstreamModule.artists = function (callback) { diff --git a/public/js/mstream.js b/public/js/mstream.js index d4f6063..77bac8e 100755 --- a/public/js/mstream.js +++ b/public/js/mstream.js @@ -1345,10 +1345,10 @@ $(document).ready(function () { \ \ \ - \ -
\ + \ +
\ + \ \ -
\ \
'; @@ -1374,7 +1374,7 @@ $(document).ready(function () { title: { name: 'Song', class: 'filez', - data: 'artist' + data: 'file_location' } }; @@ -1382,8 +1382,14 @@ $(document).ready(function () { $('#search-results').html(''); $('#search-results').append('
'); + var postObject = { search: $('#search-term').val()}; + if (document.getElementById("search-in-artists") && document.getElementById("search-in-artists").checked === false) { postObject.noArtists = false; } + if (document.getElementById("search-in-albums") && document.getElementById("search-in-albums").checked === false) { postObject.noAlbums = false; } + if (document.getElementById("search-in-filepaths") && document.getElementById("search-in-filepaths").checked === false) { postObject.noFiles = false; } + if (document.getElementById("search-in-titles") && document.getElementById("search-in-titles").checked === false) { postObject.noTitles = false; } + // Send AJAX Request - MSTREAMAPI.search($('#search-term').val(), function(res, error) { + MSTREAMAPI.search(postObject, function(res, error) { if (error !== false) { $('#search-results').html('
Server call failed
'); return boilerplateFailure(response, error); @@ -1394,7 +1400,11 @@ $(document).ready(function () { Object.keys(res).forEach(function (key) { res[key].forEach(function (value, i) { // perform some operation on a value; - searchList.push(`
${searchMap[key].name}: ${value.name}
`); + if (value.filepath) { + searchList.push(`
${searchMap[key].name}: ${value.name}
`); + } else { + searchList.push(`
${searchMap[key].name}: ${value.name}
`); + } }); });