Rewrote how local plex library is indexed and what it returns. After searching plex the response is separated into three classes by types (movie, show & episode). Plex also has a function for inputing a (tmdb)movie object and searching for matches of name & type in plex. If a match the object matchedInPlex variable is set to true.

This commit is contained in:
2018-10-29 21:01:16 +01:00
parent 8f5bd44e4d
commit 161a466ab7
8 changed files with 171 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
const configuration = require('src/config/configuration').getInstance();
const Plex = require('src/plex/plex');
const plex = new Plex(configuration.get('plex', 'ip'));
/**
* Controller: Search plex for movies, shows and episodes by query
* @param {Request} req http request variable
* @param {Response} res
* @returns {Callback}
*/
function searchPlexController(req, res) {
const { query, type } = req.query;
plex.search(query, type)
.then((movies) => {
if (movies.length > 0) {
res.send(movies);
} else {
res.status(404).send({ success: false, error: 'Search query did not give any results from plex.'})
}
}).catch((error) => {
res.status(500).send({ success: false, error: error.message });
});
}
module.exports = searchPlexController;