From 815aaedffb8deac773b0c2f23daeab1c37c49dca Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Wed, 8 Apr 2020 22:54:19 +0200 Subject: [PATCH] Changed tmdb constructor to have apiKey as first parameter. If cache is not defined we use redis. --- seasoned_api/src/tmdb/tmdb.js | 5 +++-- .../src/webserver/controllers/list/listController.js | 4 +--- seasoned_api/src/webserver/controllers/movie/credits.js | 6 ++---- seasoned_api/src/webserver/controllers/movie/info.js | 4 +--- .../src/webserver/controllers/movie/releaseDates.js | 6 ++---- seasoned_api/src/webserver/controllers/person/info.js | 4 +--- .../src/webserver/controllers/search/movieSearch.js | 4 +--- .../src/webserver/controllers/search/multiSearch.js | 4 +--- .../src/webserver/controllers/search/personSearch.js | 4 +--- .../src/webserver/controllers/search/showSearch.js | 4 +--- seasoned_api/src/webserver/controllers/show/credits.js | 7 ++----- seasoned_api/src/webserver/controllers/show/info.js | 4 +--- 12 files changed, 17 insertions(+), 39 deletions(-) diff --git a/seasoned_api/src/tmdb/tmdb.js b/seasoned_api/src/tmdb/tmdb.js index 19a8bea..1e6a8cc 100644 --- a/seasoned_api/src/tmdb/tmdb.js +++ b/seasoned_api/src/tmdb/tmdb.js @@ -27,9 +27,10 @@ const tmdbErrorResponse = (error, typeString=undefined) => { } class TMDB { - constructor(cache, apiKey, tmdbLibrary) { - this.cache = cache || redisCache; + constructor(apiKey, cache, tmdbLibrary) { this.tmdbLibrary = tmdbLibrary || moviedb(apiKey); + + this.cache = cache || redisCache; this.cacheTags = { multiSearch: 'mus', movieSearch: 'mos', diff --git a/seasoned_api/src/webserver/controllers/list/listController.js b/seasoned_api/src/webserver/controllers/list/listController.js index 4e7806f..db71722 100644 --- a/seasoned_api/src/webserver/controllers/list/listController.js +++ b/seasoned_api/src/webserver/controllers/list/listController.js @@ -1,8 +1,6 @@ const configuration = require('src/config/configuration').getInstance(); -const Cache = require('src/tmdb/cache'); const TMDB = require('src/tmdb/tmdb'); -const cache = new Cache(); -const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey')); +const tmdb = new TMDB(configuration.get('tmdb', 'apiKey')); // there should be a translate function from query params to // tmdb list that is valid. Should it be a helper function or does it diff --git a/seasoned_api/src/webserver/controllers/movie/credits.js b/seasoned_api/src/webserver/controllers/movie/credits.js index 542adfc..dbf5ff2 100644 --- a/seasoned_api/src/webserver/controllers/movie/credits.js +++ b/seasoned_api/src/webserver/controllers/movie/credits.js @@ -1,9 +1,7 @@ const configuration = require('src/config/configuration').getInstance(); -const Cache = require('src/tmdb/cache'); const TMDB = require('src/tmdb/tmdb'); -const cache = new Cache(); -const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey')); +const tmdb = new TMDB(configuration.get('tmdb', 'apiKey')); const movieCreditsController = (req, res) => { const movieId = req.params.id; @@ -23,4 +21,4 @@ const movieCreditsController = (req, res) => { }) } -module.exports = movieCreditsController; \ No newline at end of file +module.exports = movieCreditsController; diff --git a/seasoned_api/src/webserver/controllers/movie/info.js b/seasoned_api/src/webserver/controllers/movie/info.js index 91d8391..76cbe21 100644 --- a/seasoned_api/src/webserver/controllers/movie/info.js +++ b/seasoned_api/src/webserver/controllers/movie/info.js @@ -1,9 +1,7 @@ const configuration = require('src/config/configuration').getInstance(); -const Cache = require('src/tmdb/cache'); const TMDB = require('src/tmdb/tmdb'); const Plex = require('src/plex/plex'); -const cache = new Cache(); -const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey')); +const tmdb = new TMDB(configuration.get('tmdb', 'apiKey')); const plex = new Plex(configuration.get('plex', 'ip')); function handleError(error, res) { diff --git a/seasoned_api/src/webserver/controllers/movie/releaseDates.js b/seasoned_api/src/webserver/controllers/movie/releaseDates.js index c9797de..4a87c6a 100644 --- a/seasoned_api/src/webserver/controllers/movie/releaseDates.js +++ b/seasoned_api/src/webserver/controllers/movie/releaseDates.js @@ -1,9 +1,7 @@ const configuration = require('src/config/configuration').getInstance(); -const Cache = require('src/tmdb/cache'); const TMDB = require('src/tmdb/tmdb'); -const cache = new Cache(); -const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey')); +const tmdb = new TMDB(configuration.get('tmdb', 'apiKey')); const movieReleaseDatesController = (req, res) => { const movieId = req.params.id; @@ -23,4 +21,4 @@ const movieReleaseDatesController = (req, res) => { }) } -module.exports = movieReleaseDatesController; \ No newline at end of file +module.exports = movieReleaseDatesController; diff --git a/seasoned_api/src/webserver/controllers/person/info.js b/seasoned_api/src/webserver/controllers/person/info.js index ea24d7a..1af2654 100644 --- a/seasoned_api/src/webserver/controllers/person/info.js +++ b/seasoned_api/src/webserver/controllers/person/info.js @@ -1,8 +1,6 @@ const configuration = require('src/config/configuration').getInstance(); -const Cache = require('src/tmdb/cache'); const TMDB = require('src/tmdb/tmdb'); -const cache = new Cache(); -const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey')); +const tmdb = new TMDB(configuration.get('tmdb', 'apiKey')); /** * Controller: Retrieve information for a person diff --git a/seasoned_api/src/webserver/controllers/search/movieSearch.js b/seasoned_api/src/webserver/controllers/search/movieSearch.js index e9b7ffa..22b5740 100644 --- a/seasoned_api/src/webserver/controllers/search/movieSearch.js +++ b/seasoned_api/src/webserver/controllers/search/movieSearch.js @@ -1,9 +1,7 @@ const configuration = require('src/config/configuration').getInstance(); -const Cache = require('src/tmdb/cache'); const TMDB = require('src/tmdb/tmdb'); const SearchHistory = require('src/searchHistory/searchHistory'); -const cache = new Cache(); -const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey')); +const tmdb = new TMDB(configuration.get('tmdb', 'apiKey')); const searchHistory = new SearchHistory(); /** diff --git a/seasoned_api/src/webserver/controllers/search/multiSearch.js b/seasoned_api/src/webserver/controllers/search/multiSearch.js index f0a3810..a9cc40a 100644 --- a/seasoned_api/src/webserver/controllers/search/multiSearch.js +++ b/seasoned_api/src/webserver/controllers/search/multiSearch.js @@ -1,9 +1,7 @@ const configuration = require('src/config/configuration').getInstance(); -const Cache = require('src/tmdb/cache'); const TMDB = require('src/tmdb/tmdb'); const SearchHistory = require('src/searchHistory/searchHistory'); -const cache = new Cache(); -const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey')); +const tmdb = new TMDB(configuration.get('tmdb', 'apiKey')); const searchHistory = new SearchHistory(); function checkAndCreateJsonResponse(result) { diff --git a/seasoned_api/src/webserver/controllers/search/personSearch.js b/seasoned_api/src/webserver/controllers/search/personSearch.js index dcb7b2a..88d7989 100644 --- a/seasoned_api/src/webserver/controllers/search/personSearch.js +++ b/seasoned_api/src/webserver/controllers/search/personSearch.js @@ -1,9 +1,7 @@ const configuration = require('src/config/configuration').getInstance(); -const Cache = require('src/tmdb/cache'); const TMDB = require('src/tmdb/tmdb'); const SearchHistory = require('src/searchHistory/searchHistory'); -const cache = new Cache(); -const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey')); +const tmdb = new TMDB(configuration.get('tmdb', 'apiKey')); const searchHistory = new SearchHistory(); /** diff --git a/seasoned_api/src/webserver/controllers/search/showSearch.js b/seasoned_api/src/webserver/controllers/search/showSearch.js index fc77cae..b2d81b6 100644 --- a/seasoned_api/src/webserver/controllers/search/showSearch.js +++ b/seasoned_api/src/webserver/controllers/search/showSearch.js @@ -1,9 +1,7 @@ const SearchHistory = require('src/searchHistory/searchHistory'); const configuration = require('src/config/configuration').getInstance(); -const Cache = require('src/tmdb/cache'); const TMDB = require('src/tmdb/tmdb'); -const cache = new Cache(); -const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey')); +const tmdb = new TMDB(configuration.get('tmdb', 'apiKey')); const searchHistory = new SearchHistory(); /** diff --git a/seasoned_api/src/webserver/controllers/show/credits.js b/seasoned_api/src/webserver/controllers/show/credits.js index 7974f1f..f146391 100644 --- a/seasoned_api/src/webserver/controllers/show/credits.js +++ b/seasoned_api/src/webserver/controllers/show/credits.js @@ -1,9 +1,6 @@ const configuration = require('src/config/configuration').getInstance(); -const Cache = require('src/tmdb/cache'); const TMDB = require('src/tmdb/tmdb'); - -const cache = new Cache(); -const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey')); +const tmdb = new TMDB(configuration.get('tmdb', 'apiKey')); const showCreditsController = (req, res) => { const showId = req.params.id; @@ -23,4 +20,4 @@ const showCreditsController = (req, res) => { }) } -module.exports = showCreditsController; \ No newline at end of file +module.exports = showCreditsController; diff --git a/seasoned_api/src/webserver/controllers/show/info.js b/seasoned_api/src/webserver/controllers/show/info.js index e335b15..340dc8b 100644 --- a/seasoned_api/src/webserver/controllers/show/info.js +++ b/seasoned_api/src/webserver/controllers/show/info.js @@ -1,9 +1,7 @@ const configuration = require('src/config/configuration').getInstance(); -const Cache = require('src/tmdb/cache'); const TMDB = require('src/tmdb/tmdb'); const Plex = require('src/plex/plex'); -const cache = new Cache(); -const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey')); +const tmdb = new TMDB(configuration.get('tmdb', 'apiKey')); const plex = new Plex(configuration.get('plex', 'ip')); function handleError(error, res) {