* Automaticly fixable eslint issues, mostly 3 -> 2 space indentation * fix: updated plex_userid to camelcase * Linted and some consistency refactor on middleware * eslint uses ecmaversion 2020 & allow empty catch rule * Started linting source files * Fixed eslint errors & improved a lot of error handling * Set 2 eslint rules as warning temporarly * Updated all import statements to be relative * Updated mocha & nyc, resolved all lint issues in tests/ * Updated mocha & nyc. Removed production config. Updated gitignore * Updated test commands to omit system tests, no exit code * Updated test configuration w/ missing keys * Chai modules defined in package.json & resolved linting errors * Dockerfile copies development.example -> production.json. Simplified commands * All api calls from tests use same chaiHttp implementation Removes a list of fetch alternatives after being replaced by chaiHttp: - request - request-promise - supertest - supertest-as-promised * Tests should use redis (mock) cache, not tmdb sqlite cache * Disabled test asADeveloperIWantTheServerToStart * Re-enable tests/system * Use chaiHttp in asAUserIWantToRequestAMovie. * Fixed redis expire & mock implmentation * Replaced all fetch alternatives from source code and package.json * Pass error from tmdb api back to client as errorMessage * Updated authentication middleware to handle checks consitenctly * Prevent assert error when checking request status, returns success 200 * Resolved merge conflicts * Only build and publish docker container when branch master
56 lines
1.7 KiB
JavaScript
56 lines
1.7 KiB
JavaScript
const configuration = require("../../../config/configuration").getInstance();
|
|
const TMDB = require("../../../tmdb/tmdb");
|
|
const Plex = require("../../../plex/plex");
|
|
|
|
const tmdb = new TMDB(configuration.get("tmdb", "apiKey"));
|
|
const plex = new Plex(configuration.get("plex", "ip"));
|
|
|
|
/**
|
|
* Controller: Retrieve information for a movie
|
|
* @param {Request} req http request variable
|
|
* @param {Response} res
|
|
* @returns {Callback}
|
|
*/
|
|
async function movieInfoController(req, res) {
|
|
const movieId = req.params.id;
|
|
|
|
let credits = req.query?.credits;
|
|
let releaseDates = req.query?.release_dates;
|
|
let checkExistance = req.query?.check_existance;
|
|
|
|
credits = credits?.toLowerCase() === "true";
|
|
releaseDates = releaseDates?.toLowerCase() === "true";
|
|
checkExistance = checkExistance?.toLowerCase() === "true";
|
|
|
|
const tmdbQueue = [tmdb.movieInfo(movieId)];
|
|
if (credits) tmdbQueue.push(tmdb.movieCredits(movieId));
|
|
if (releaseDates) tmdbQueue.push(tmdb.movieReleaseDates(movieId));
|
|
|
|
try {
|
|
const [Movie, Credits, ReleaseDates] = await Promise.all(tmdbQueue);
|
|
|
|
const movie = Movie.createJsonResponse();
|
|
if (Credits) movie.credits = Credits.createJsonResponse();
|
|
if (ReleaseDates)
|
|
movie.releaseDates = ReleaseDates.createJsonResponse().results;
|
|
|
|
if (checkExistance) {
|
|
try {
|
|
movie.exists_in_plex = await plex.existsInPlex(movie);
|
|
} catch {}
|
|
}
|
|
|
|
return res.send(movie);
|
|
} catch (error) {
|
|
return res.status(error?.statusCode || 500).send({
|
|
success: false,
|
|
errorMessage: error?.errorMessage,
|
|
message:
|
|
error?.message ||
|
|
`An unexpected error occured while requesting info for with id: ${movieId}`
|
|
});
|
|
}
|
|
}
|
|
|
|
module.exports = movieInfoController;
|