| @@ -7,7 +7,7 @@ | |||||||
|   }, |   }, | ||||||
|   "main": "webserver/server.js", |   "main": "webserver/server.js", | ||||||
|   "scripts": { |   "scripts": { | ||||||
|     "start": "cross-env SEASONED_CONFIG=conf/development.json PROD=true NODE_PATH=. babel-node src/webserver/server.js", |     "start": "cross-env SEASONED_CONFIG=conf/development.json NODE_ENV=production NODE_PATH=. babel-node src/webserver/server.js", | ||||||
|     "test": "cross-env SEASONED_CONFIG=conf/test.json NODE_PATH=. mocha --require @babel/register --recursive test/unit test/system", |     "test": "cross-env SEASONED_CONFIG=conf/test.json NODE_PATH=. mocha --require @babel/register --recursive test/unit test/system", | ||||||
|     "coverage": "cross-env SEASONED_CONFIG=conf/test.json NODE_PATH=. nyc mocha --require @babel/register --recursive test && nyc report --reporter=text-lcov | coveralls", |     "coverage": "cross-env SEASONED_CONFIG=conf/test.json NODE_PATH=. nyc mocha --require @babel/register --recursive test && nyc report --reporter=text-lcov | coveralls", | ||||||
|     "lint": "./node_modules/.bin/eslint src/", |     "lint": "./node_modules/.bin/eslint src/", | ||||||
| @@ -18,7 +18,7 @@ | |||||||
|   }, |   }, | ||||||
|   "dependencies": { |   "dependencies": { | ||||||
|     "axios": "^0.18.0", |     "axios": "^0.18.0", | ||||||
|     "bcrypt": "^3.0.6", |     "bcrypt": "^5.0.1", | ||||||
|     "body-parser": "~1.18.2", |     "body-parser": "~1.18.2", | ||||||
|     "cookie-parser": "^1.4.6", |     "cookie-parser": "^1.4.6", | ||||||
|     "cross-env": "~5.1.4", |     "cross-env": "~5.1.4", | ||||||
| @@ -33,7 +33,7 @@ | |||||||
|     "redis": "^3.0.2", |     "redis": "^3.0.2", | ||||||
|     "request": "^2.87.0", |     "request": "^2.87.0", | ||||||
|     "request-promise": "^4.2", |     "request-promise": "^4.2", | ||||||
|     "sqlite3": "^4.0.0" |     "sqlite3": "^5.0.1" | ||||||
|   }, |   }, | ||||||
|   "devDependencies": { |   "devDependencies": { | ||||||
|     "@babel/core": "^7.5.5", |     "@babel/core": "^7.5.5", | ||||||
|   | |||||||
							
								
								
									
										35
									
								
								seasoned_api/src/notifications/sms.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								seasoned_api/src/notifications/sms.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,35 @@ | |||||||
|  | const request = require("request"); | ||||||
|  | const configuration = require('src/config/configuration').getInstance(); | ||||||
|  |  | ||||||
|  | const sendSMS = (message) => { | ||||||
|  |   const apiKey = configuration.get('sms', 'apikey') | ||||||
|  |  | ||||||
|  |   if (!apiKey) { | ||||||
|  |     console.warning("api key for sms not set, cannot send sms.") | ||||||
|  |     return null | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   const sender = configuration.get('sms', 'sender') | ||||||
|  |   const recipient = configuration.get('sms', 'recipient') | ||||||
|  |  | ||||||
|  |   return new Promise((resolve, reject) => { | ||||||
|  |   request.post( | ||||||
|  |     { | ||||||
|  |       url: `https://gatewayapi.com/rest/mtsms?token=${apiKey}`, | ||||||
|  |       json: true, | ||||||
|  |       body: { | ||||||
|  |         sender, | ||||||
|  |         message, | ||||||
|  |         recipients: [{ msisdn: `47${recipient}` }] | ||||||
|  |       } | ||||||
|  |     }, | ||||||
|  |     function(err, r, body) { | ||||||
|  |       console.log(err ? err : body); | ||||||
|  |       console.log("sms provider response:", body) | ||||||
|  |       resolve() | ||||||
|  |     } | ||||||
|  |   ); | ||||||
|  |   }) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | module.exports = { sendSMS } | ||||||
| @@ -10,6 +10,12 @@ const redisCache = new RedisCache(); | |||||||
|  |  | ||||||
| const sanitize = string => string.toLowerCase().replace(/[^\w]/gi, ""); | const sanitize = string => string.toLowerCase().replace(/[^\w]/gi, ""); | ||||||
|  |  | ||||||
|  | function fixedEncodeURIComponent(str) { | ||||||
|  |   return encodeURIComponent(str).replace(/[!'()*]/g, function (c) { | ||||||
|  |     return "%" + c.charCodeAt(0).toString(16).toUpperCase(); | ||||||
|  |   }); | ||||||
|  | } | ||||||
|  |  | ||||||
| const matchingTitleAndYear = (plex, tmdb) => { | const matchingTitleAndYear = (plex, tmdb) => { | ||||||
|   let matchingTitle, matchingYear; |   let matchingTitle, matchingYear; | ||||||
|  |  | ||||||
| @@ -121,15 +127,12 @@ class Plex { | |||||||
|   findPlexItemByTitleAndYear(title, year) { |   findPlexItemByTitleAndYear(title, year) { | ||||||
|     const query = { title, year }; |     const query = { title, year }; | ||||||
|  |  | ||||||
|     return this.search(query.title).then(plexSearchResults => { |     return this.search(title).then(plexResults => { | ||||||
|       const matchesInPlex = plexSearchResults.map(plex => |       const matchesInPlex = plexResults.map(plex => | ||||||
|         this.matchTmdbAndPlexMedia(plex, query) |         this.matchTmdbAndPlexMedia(plex, query) | ||||||
|       ); |       ); | ||||||
|  |       const matchesIndex = matchesInPlex.findIndex(el => el === true); | ||||||
|       if (matchesInPlex.includes(true) === false) return false; |       return matchesInPlex != -1 ? plexResults[matchesIndex] : null; | ||||||
|  |  | ||||||
|       const firstMatchIndex = matchesInPlex.indexOf(true); |  | ||||||
|       return plexSearchResults[firstMatchIndex][0]; |  | ||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @@ -152,7 +155,7 @@ class Plex { | |||||||
|       ) |       ) | ||||||
|         return false; |         return false; | ||||||
|  |  | ||||||
|       const keyUriComponent = encodeURIComponent(matchingObjectInPlex.key); |       const keyUriComponent = fixedEncodeURIComponent(matchingObjectInPlex.key); | ||||||
|       return `https://app.plex.tv/desktop#!/server/${machineIdentifier}/details?key=${keyUriComponent}`; |       return `https://app.plex.tv/desktop#!/server/${machineIdentifier}/details?key=${keyUriComponent}`; | ||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
| @@ -162,7 +165,7 @@ class Plex { | |||||||
|  |  | ||||||
|     const url = `http://${this.plexIP}:${ |     const url = `http://${this.plexIP}:${ | ||||||
|       this.plexPort |       this.plexPort | ||||||
|     }/hubs/search?query=${encodeURIComponent(query)}`; |     }/hubs/search?query=${fixedEncodeURIComponent(query)}`; | ||||||
|     const options = { |     const options = { | ||||||
|       timeout: 20000, |       timeout: 20000, | ||||||
|       headers: { Accept: "application/json" } |       headers: { Accept: "application/json" } | ||||||
|   | |||||||
| @@ -1,8 +1,14 @@ | |||||||
| const moviedb = require('km-moviedb'); | const moviedb = require("km-moviedb"); | ||||||
| const RedisCache = require('src/cache/redis') | const RedisCache = require("src/cache/redis"); | ||||||
| const redisCache = new RedisCache() | const redisCache = new RedisCache(); | ||||||
|  |  | ||||||
| const { Movie, Show, Person, Credits, ReleaseDates } = require('src/tmdb/types'); | const { | ||||||
|  |   Movie, | ||||||
|  |   Show, | ||||||
|  |   Person, | ||||||
|  |   Credits, | ||||||
|  |   ReleaseDates | ||||||
|  | } = require("src/tmdb/types"); | ||||||
|  |  | ||||||
| const tmdbErrorResponse = (error, typeString = undefined) => { | const tmdbErrorResponse = (error, typeString = undefined) => { | ||||||
|   if (error.status === 404) { |   if (error.status === 404) { | ||||||
| @@ -11,19 +17,19 @@ const tmdbErrorResponse = (error, typeString=undefined) => { | |||||||
|     throw { |     throw { | ||||||
|       status: 404, |       status: 404, | ||||||
|       message: message.slice(0, -1) + " in tmdb." |       message: message.slice(0, -1) + " in tmdb." | ||||||
|     } |     }; | ||||||
|   } else if (error.status === 401) { |   } else if (error.status === 401) { | ||||||
|     throw { |     throw { | ||||||
|       status: 401, |       status: 401, | ||||||
|       message: error.response.body.status_message |       message: error.response.body.status_message | ||||||
|     } |     }; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   throw { |   throw { | ||||||
|     status: 500, |     status: 500, | ||||||
|     message: `An unexpected error occured while fetching ${typeString} from tmdb` |     message: `An unexpected error occured while fetching ${typeString} from tmdb` | ||||||
|   } |   }; | ||||||
| } | }; | ||||||
|  |  | ||||||
| class TMDB { | class TMDB { | ||||||
|   constructor(apiKey, cache, tmdbLibrary) { |   constructor(apiKey, cache, tmdbLibrary) { | ||||||
| @@ -31,34 +37,38 @@ class TMDB { | |||||||
|  |  | ||||||
|     this.cache = cache || redisCache; |     this.cache = cache || redisCache; | ||||||
|     this.cacheTags = { |     this.cacheTags = { | ||||||
|       multiSearch: 'mus',  |       multiSearch: "mus", | ||||||
|       movieSearch: 'mos',  |       movieSearch: "mos", | ||||||
|       showSearch: 'ss', |       showSearch: "ss", | ||||||
|       personSearch: 'ps', |       personSearch: "ps", | ||||||
|       movieInfo: 'mi', |       movieInfo: "mi", | ||||||
|       movieCredits: 'mc', |       movieCredits: "mc", | ||||||
|       movieReleaseDates: 'mrd', |       movieReleaseDates: "mrd", | ||||||
|       showInfo: 'si', |       movieImages: "mimg", | ||||||
|       showCredits: 'sc', |       showInfo: "si", | ||||||
|       personInfo: 'pi', |       showCredits: "sc", | ||||||
|       miscNowPlayingMovies: 'npm', |       personInfo: "pi", | ||||||
|       miscPopularMovies: 'pm', |       personCredits: "pc", | ||||||
|       miscTopRatedMovies: 'tpm', |       miscNowPlayingMovies: "npm", | ||||||
|       miscUpcomingMovies: 'um', |       miscPopularMovies: "pm", | ||||||
|       tvOnTheAir: 'toa', |       miscTopRatedMovies: "tpm", | ||||||
|       miscPopularTvs: 'pt', |       miscUpcomingMovies: "um", | ||||||
|       miscTopRatedTvs: 'trt', |       tvOnTheAir: "toa", | ||||||
|  |       miscPopularTvs: "pt", | ||||||
|  |       miscTopRatedTvs: "trt" | ||||||
|     }; |     }; | ||||||
|     this.defaultTTL = 86400 |     this.defaultTTL = 86400; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   getFromCacheOrFetchFromTmdb(cacheKey, tmdbMethod, query) { |   getFromCacheOrFetchFromTmdb(cacheKey, tmdbMethod, query) { | ||||||
|     return new Promise((resolve, reject) => this.cache.get(cacheKey) |     return new Promise((resolve, reject) => | ||||||
|  |       this.cache | ||||||
|  |         .get(cacheKey) | ||||||
|         .then(resolve) |         .then(resolve) | ||||||
|         .catch(() => this.tmdb(tmdbMethod, query)) |         .catch(() => this.tmdb(tmdbMethod, query)) | ||||||
|         .then(resolve) |         .then(resolve) | ||||||
|         .catch(error => reject(tmdbErrorResponse(error, tmdbMethod))) |         .catch(error => reject(tmdbErrorResponse(error, tmdbMethod))) | ||||||
|     ) |     ); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
| @@ -72,9 +82,9 @@ class TMDB { | |||||||
|     const query = { id: identifier }; |     const query = { id: identifier }; | ||||||
|     const cacheKey = `tmdb/${this.cacheTags.movieInfo}:${identifier}`; |     const cacheKey = `tmdb/${this.cacheTags.movieInfo}:${identifier}`; | ||||||
|  |  | ||||||
|     return this.getFromCacheOrFetchFromTmdb(cacheKey, 'movieInfo', query) |     return this.getFromCacheOrFetchFromTmdb(cacheKey, "movieInfo", query) | ||||||
|       .then(movie => this.cache.set(cacheKey, movie, this.defaultTTL)) |       .then(movie => this.cache.set(cacheKey, movie, this.defaultTTL)) | ||||||
|       .then(movie => Movie.convertFromTmdbResponse(movie)) |       .then(movie => Movie.convertFromTmdbResponse(movie)); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
| @@ -83,12 +93,12 @@ class TMDB { | |||||||
|    * @returns {Promise} movie cast object |    * @returns {Promise} movie cast object | ||||||
|    */ |    */ | ||||||
|   movieCredits(identifier) { |   movieCredits(identifier) { | ||||||
|     const query = { id: identifier } |     const query = { id: identifier }; | ||||||
|     const cacheKey = `tmdb/${this.cacheTags.movieCredits}:${identifier}` |     const cacheKey = `tmdb/${this.cacheTags.movieCredits}:${identifier}`; | ||||||
|  |  | ||||||
|     return this.getFromCacheOrFetchFromTmdb(cacheKey, 'movieCredits', query) |     return this.getFromCacheOrFetchFromTmdb(cacheKey, "movieCredits", query) | ||||||
|       .then(credits => this.cache.set(cacheKey, credits, this.defaultTTL)) |       .then(credits => this.cache.set(cacheKey, credits, this.defaultTTL)) | ||||||
|       .then(credits => Credits.convertFromTmdbResponse(credits)) |       .then(credits => Credits.convertFromTmdbResponse(credits)); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
| @@ -115,18 +125,18 @@ class TMDB { | |||||||
|     const query = { id: identifier }; |     const query = { id: identifier }; | ||||||
|     const cacheKey = `tmdb/${this.cacheTags.showInfo}:${identifier}`; |     const cacheKey = `tmdb/${this.cacheTags.showInfo}:${identifier}`; | ||||||
|  |  | ||||||
|     return this.getFromCacheOrFetchFromTmdb(cacheKey, 'tvInfo', query) |     return this.getFromCacheOrFetchFromTmdb(cacheKey, "tvInfo", query) | ||||||
|       .then(show => this.cache.set(cacheKey, show, this.defaultTTL)) |       .then(show => this.cache.set(cacheKey, show, this.defaultTTL)) | ||||||
|       .then(show => Show.convertFromTmdbResponse(show)) |       .then(show => Show.convertFromTmdbResponse(show)); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   showCredits(identifier) { |   showCredits(identifier) { | ||||||
|     const query = { id: identifier } |     const query = { id: identifier }; | ||||||
|     const cacheKey = `tmdb/${this.cacheTags.showCredits}:${identifier}` |     const cacheKey = `tmdb/${this.cacheTags.showCredits}:${identifier}`; | ||||||
|  |  | ||||||
|     return this.getFromCacheOrFetchFromTmdb(cacheKey, 'tvCredits', query) |     return this.getFromCacheOrFetchFromTmdb(cacheKey, "tvCredits", query) | ||||||
|       .then(credits => this.cache.set(cacheKey, credits, this.defaultTTL)) |       .then(credits => this.cache.set(cacheKey, credits, this.defaultTTL)) | ||||||
|       .then(credits => Credits.convertFromTmdbResponse(credits)) |       .then(credits => Credits.convertFromTmdbResponse(credits)); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
| @@ -139,16 +149,29 @@ class TMDB { | |||||||
|     const query = { id: identifier }; |     const query = { id: identifier }; | ||||||
|     const cacheKey = `tmdb/${this.cacheTags.personInfo}:${identifier}`; |     const cacheKey = `tmdb/${this.cacheTags.personInfo}:${identifier}`; | ||||||
|  |  | ||||||
|     return this.getFromCacheOrFetchFromTmdb(cacheKey, 'personInfo', query) |     return this.getFromCacheOrFetchFromTmdb(cacheKey, "personInfo", query) | ||||||
|       .then(person => this.cache.set(cacheKey, person, this.defaultTTL)) |       .then(person => this.cache.set(cacheKey, person, this.defaultTTL)) | ||||||
|       .then(person => Person.convertFromTmdbResponse(person)) |       .then(person => Person.convertFromTmdbResponse(person)); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   multiSearch(search_query, page=1, adult=true) { |   personCredits(identifier) { | ||||||
|     const query = { query: search_query, page: page, include_adult: adult }; |     const query = { id: identifier }; | ||||||
|     const cacheKey = `tmdb/${this.cacheTags.multiSearch}:${page}:${search_query}:${adult}`; |     const cacheKey = `tmdb/${this.cacheTags.personCredits}:${identifier}`; | ||||||
|  |  | ||||||
|     return this.getFromCacheOrFetchFromTmdb(cacheKey, 'searchMulti', query) |     return this.getFromCacheOrFetchFromTmdb( | ||||||
|  |       cacheKey, | ||||||
|  |       "personCombinedCredits", | ||||||
|  |       query | ||||||
|  |     ) | ||||||
|  |       .then(credits => this.cache.set(cacheKey, credits, this.defaultTTL)) | ||||||
|  |       .then(credits => Credits.convertFromTmdbResponse(credits)); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   multiSearch(search_query, page = 1, include_adult = true) { | ||||||
|  |     const query = { query: search_query, page, include_adult }; | ||||||
|  |     const cacheKey = `tmdb/${this.cacheTags.multiSearch}:${page}:${search_query}:${include_adult}`; | ||||||
|  |  | ||||||
|  |     return this.getFromCacheOrFetchFromTmdb(cacheKey, "searchMulti", query) | ||||||
|       .then(response => this.cache.set(cacheKey, response, this.defaultTTL)) |       .then(response => this.cache.set(cacheKey, response, this.defaultTTL)) | ||||||
|       .then(response => this.mapResults(response)); |       .then(response => this.mapResults(response)); | ||||||
|   } |   } | ||||||
| @@ -159,13 +182,13 @@ class TMDB { | |||||||
|    * @param {Number} page representing pagination of results |    * @param {Number} page representing pagination of results | ||||||
|    * @returns {Promise} dict with query results, current page and total_pages |    * @returns {Promise} dict with query results, current page and total_pages | ||||||
|    */ |    */ | ||||||
|   movieSearch(query, page=1, adult=true) { |   movieSearch(search_query, page = 1, include_adult = true) { | ||||||
|     const tmdbquery = { query: query, page: page, adult: adult }; |     const tmdbquery = { query: search_query, page, include_adult }; | ||||||
|     const cacheKey = `tmdb/${this.cacheTags.movieSearch}:${page}:${query}:${adult}`; |     const cacheKey = `tmdb/${this.cacheTags.movieSearch}:${page}:${search_query}:${include_adult}`; | ||||||
|  |  | ||||||
|     return this.getFromCacheOrFetchFromTmdb(cacheKey, 'searchMovie', query) |     return this.getFromCacheOrFetchFromTmdb(cacheKey, "searchMovie", tmdbquery) | ||||||
|       .then(response => this.cache.set(cacheKey, response, this.defaultTTL)) |       .then(response => this.cache.set(cacheKey, response, this.defaultTTL)) | ||||||
|       .then(response => this.mapResults(response, 'movie')) |       .then(response => this.mapResults(response, "movie")); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
| @@ -174,13 +197,13 @@ class TMDB { | |||||||
|    * @param {Number} page representing pagination of results |    * @param {Number} page representing pagination of results | ||||||
|    * @returns {Promise} dict with query results, current page and total_pages |    * @returns {Promise} dict with query results, current page and total_pages | ||||||
|    */ |    */ | ||||||
|   showSearch(query, page=1) { |   showSearch(search_query, page = 1, include_adult = true) { | ||||||
|     const tmdbquery = { query: query, page: page }; |     const tmdbquery = { query: search_query, page, include_adult }; | ||||||
|     const cacheKey = `tmdb/${this.cacheTags.showSearch}:${page}:${query}`; |     const cacheKey = `tmdb/${this.cacheTags.showSearch}:${page}:${search_query}:${include_adult}`; | ||||||
|  |  | ||||||
|     return this.getFromCacheOrFetchFromTmdb(cacheKey, 'searchTv', query) |     return this.getFromCacheOrFetchFromTmdb(cacheKey, "searchTv", tmdbquery) | ||||||
|       .then(response => this.cache.set(cacheKey, response, this.defaultTTL)) |       .then(response => this.cache.set(cacheKey, response, this.defaultTTL)) | ||||||
|       .then(response => this.mapResults(response, 'show')) |       .then(response => this.mapResults(response, "show")); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
| @@ -189,14 +212,13 @@ class TMDB { | |||||||
|    * @param {Number} page representing pagination of results |    * @param {Number} page representing pagination of results | ||||||
|    * @returns {Promise} dict with query results, current page and total_pages |    * @returns {Promise} dict with query results, current page and total_pages | ||||||
|    */ |    */ | ||||||
|   personSearch(query, page=1) { |   personSearch(search_query, page = 1, include_adult = true) { | ||||||
|  |     const tmdbquery = { query: search_query, page, include_adult }; | ||||||
|  |     const cacheKey = `tmdb/${this.cacheTags.personSearch}:${page}:${search_query}:${include_adult}`; | ||||||
|  |  | ||||||
|     const tmdbquery = { query: query, page: page, include_adult: true }; |     return this.getFromCacheOrFetchFromTmdb(cacheKey, "searchPerson", tmdbquery) | ||||||
|     const cacheKey = `tmdb/${this.cacheTags.personSearch}:${page}:${query}:${include_adult}`; |  | ||||||
|  |  | ||||||
|     return this.getFromCacheOrFetchFromTmdb(cacheKey, 'searchPerson', query) |  | ||||||
|       .then(response => this.cache.set(cacheKey, response, this.defaultTTL)) |       .then(response => this.cache.set(cacheKey, response, this.defaultTTL)) | ||||||
|       .then(response => this.mapResults(response, 'person')) |       .then(response => this.mapResults(response, "person")); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   movieList(listname, page = 1) { |   movieList(listname, page = 1) { | ||||||
| @@ -205,7 +227,7 @@ class TMDB { | |||||||
|  |  | ||||||
|     return this.getFromCacheOrFetchFromTmdb(cacheKey, listname, query) |     return this.getFromCacheOrFetchFromTmdb(cacheKey, listname, query) | ||||||
|       .then(response => this.cache.set(cacheKey, response, this.defaultTTL)) |       .then(response => this.cache.set(cacheKey, response, this.defaultTTL)) | ||||||
|       .then(response => this.mapResults(response, 'movie')) |       .then(response => this.mapResults(response, "movie")); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   showList(listname, page = 1) { |   showList(listname, page = 1) { | ||||||
| @@ -214,7 +236,7 @@ class TMDB { | |||||||
|  |  | ||||||
|     return this.getFromCacheOrFetchFromTmdb(cacheKey, listName, query) |     return this.getFromCacheOrFetchFromTmdb(cacheKey, listName, query) | ||||||
|       .then(response => this.cache.set(cacheKey, response, this.defaultTTL)) |       .then(response => this.cache.set(cacheKey, response, this.defaultTTL)) | ||||||
|       .then(response => this.mapResults(response, 'show')) |       .then(response => this.mapResults(response, "show")); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
| @@ -224,26 +246,25 @@ class TMDB { | |||||||
|    * @returns {Promise} dict with tmdb results, mapped as movie/show objects. |    * @returns {Promise} dict with tmdb results, mapped as movie/show objects. | ||||||
|    */ |    */ | ||||||
|   mapResults(response, type = undefined) { |   mapResults(response, type = undefined) { | ||||||
|  |  | ||||||
|     let results = response.results.map(result => { |     let results = response.results.map(result => { | ||||||
|       if (type === 'movie' || result.media_type === 'movie') { |       if (type === "movie" || result.media_type === "movie") { | ||||||
|         const movie = Movie.convertFromTmdbResponse(result) |         const movie = Movie.convertFromTmdbResponse(result); | ||||||
|         return movie.createJsonResponse() |         return movie.createJsonResponse(); | ||||||
|       } else if (type === 'show' || result.media_type === 'tv') { |       } else if (type === "show" || result.media_type === "tv") { | ||||||
|         const show = Show.convertFromTmdbResponse(result) |         const show = Show.convertFromTmdbResponse(result); | ||||||
|         return show.createJsonResponse() |         return show.createJsonResponse(); | ||||||
|       } else if (type === 'person' || result.media_type === 'person') { |       } else if (type === "person" || result.media_type === "person") { | ||||||
|         const person = Person.convertFromTmdbResponse(result) |         const person = Person.convertFromTmdbResponse(result); | ||||||
|         return person.createJsonResponse() |         return person.createJsonResponse(); | ||||||
|       } |       } | ||||||
|     }) |     }); | ||||||
|  |  | ||||||
|     return { |     return { | ||||||
|       results: results, |       results: results, | ||||||
|       page: response.page, |       page: response.page, | ||||||
|       total_results: response.total_results, |       total_results: response.total_results, | ||||||
|       total_pages: response.total_pages |       total_pages: response.total_pages | ||||||
|     } |     }; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
| @@ -268,9 +289,6 @@ class TMDB { | |||||||
|       } |       } | ||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| module.exports = TMDB; | module.exports = TMDB; | ||||||
|   | |||||||
| @@ -1,20 +1,55 @@ | |||||||
|  | import Movie from "./movie"; | ||||||
|  | import Show from "./show"; | ||||||
|  |  | ||||||
| class Credits { | class Credits { | ||||||
|   constructor(id, cast = [], crew = []) { |   constructor(id, cast = [], crew = []) { | ||||||
|     this.id = id; |     this.id = id; | ||||||
|     this.cast = cast; |     this.cast = cast; | ||||||
|     this.crew = crew; |     this.crew = crew; | ||||||
|     this.type = 'credits'; |     this.type = "credits"; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   static convertFromTmdbResponse(response) { |   static convertFromTmdbResponse(response) { | ||||||
|     const { id, cast, crew } = response; |     const { id, cast, crew } = response; | ||||||
|  |  | ||||||
|     const allCast = cast.map(cast =>  |     const allCast = cast.map(cast => { | ||||||
|       new CastMember(cast.character, cast.gender, cast.id, cast.name, cast.profile_path)) |       if (cast["media_type"]) { | ||||||
|     const allCrew = crew.map(crew => |         if (cast.media_type === "movie") { | ||||||
|       new CrewMember(crew.department, crew.gender, crew.id, crew.job, crew.name, crew.profile_path)) |           return CreditedMovie.convertFromTmdbResponse(cast); | ||||||
|  |         } else if (cast.media_type === "tv") { | ||||||
|  |           return CreditedShow.convertFromTmdbResponse(cast); | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |  | ||||||
|     return new Credits(id, allCast, allCrew) |       return new CastMember( | ||||||
|  |         cast.character, | ||||||
|  |         cast.gender, | ||||||
|  |         cast.id, | ||||||
|  |         cast.name, | ||||||
|  |         cast.profile_path | ||||||
|  |       ); | ||||||
|  |     }); | ||||||
|  |  | ||||||
|  |     const allCrew = crew.map(crew => { | ||||||
|  |       if (cast["media_type"]) { | ||||||
|  |         if (cast.media_type === "movie") { | ||||||
|  |           return CreditedMovie.convertFromTmdbResponse(cast); | ||||||
|  |         } else if (cast.media_type === "tv") { | ||||||
|  |           return CreditedShow.convertFromTmdbResponse(cast); | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       return new CrewMember( | ||||||
|  |         crew.department, | ||||||
|  |         crew.gender, | ||||||
|  |         crew.id, | ||||||
|  |         crew.job, | ||||||
|  |         crew.name, | ||||||
|  |         crew.profile_path | ||||||
|  |       ); | ||||||
|  |     }); | ||||||
|  |  | ||||||
|  |     return new Credits(id, allCast, allCrew); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   createJsonResponse() { |   createJsonResponse() { | ||||||
| @@ -22,7 +57,7 @@ class Credits { | |||||||
|       id: this.id, |       id: this.id, | ||||||
|       cast: this.cast.map(cast => cast.createJsonResponse()), |       cast: this.cast.map(cast => cast.createJsonResponse()), | ||||||
|       crew: this.crew.map(crew => crew.createJsonResponse()) |       crew: this.crew.map(crew => crew.createJsonResponse()) | ||||||
|     } |     }; | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -33,7 +68,7 @@ class CastMember { | |||||||
|     this.id = id; |     this.id = id; | ||||||
|     this.name = name; |     this.name = name; | ||||||
|     this.profile_path = profile_path; |     this.profile_path = profile_path; | ||||||
|     this.type = 'cast member'; |     this.type = "person"; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   createJsonResponse() { |   createJsonResponse() { | ||||||
| @@ -44,7 +79,7 @@ class CastMember { | |||||||
|       name: this.name, |       name: this.name, | ||||||
|       profile_path: this.profile_path, |       profile_path: this.profile_path, | ||||||
|       type: this.type |       type: this.type | ||||||
|     } |     }; | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -56,7 +91,7 @@ class CrewMember { | |||||||
|     this.job = job; |     this.job = job; | ||||||
|     this.name = name; |     this.name = name; | ||||||
|     this.profile_path = profile_path; |     this.profile_path = profile_path; | ||||||
|     this.type = 'crew member'; |     this.type = "person"; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   createJsonResponse() { |   createJsonResponse() { | ||||||
| @@ -68,8 +103,11 @@ class CrewMember { | |||||||
|       name: this.name, |       name: this.name, | ||||||
|       profile_path: this.profile_path, |       profile_path: this.profile_path, | ||||||
|       type: this.type |       type: this.type | ||||||
|     } |     }; | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | class CreditedMovie extends Movie {} | ||||||
|  | class CreditedShow extends Show {} | ||||||
|  |  | ||||||
| module.exports = Credits; | module.exports = Credits; | ||||||
|   | |||||||
| @@ -1,23 +1,54 @@ | |||||||
| class Person { | class Person { | ||||||
|   constructor(id, name, poster=undefined, birthday=undefined, deathday=undefined, |   constructor( | ||||||
|               adult=undefined, knownForDepartment=undefined) { |     id, | ||||||
|  |     name, | ||||||
|  |     poster = undefined, | ||||||
|  |     birthday = undefined, | ||||||
|  |     deathday = undefined, | ||||||
|  |     adult = undefined, | ||||||
|  |     placeOfBirth = undefined, | ||||||
|  |     biography = undefined, | ||||||
|  |     knownForDepartment = undefined | ||||||
|  |   ) { | ||||||
|     this.id = id; |     this.id = id; | ||||||
|     this.name = name; |     this.name = name; | ||||||
|     this.poster = poster; |     this.poster = poster; | ||||||
|     this.birthday = birthday; |     this.birthday = birthday; | ||||||
|     this.deathday = deathday; |     this.deathday = deathday; | ||||||
|     this.adult = adult; |     this.adult = adult; | ||||||
|  |     this.placeOfBirth = placeOfBirth; | ||||||
|  |     this.biography = biography; | ||||||
|     this.knownForDepartment = knownForDepartment; |     this.knownForDepartment = knownForDepartment; | ||||||
|     this.type = 'person'; |     this.type = "person"; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   static convertFromTmdbResponse(response) { |   static convertFromTmdbResponse(response) { | ||||||
|     const { id, name, profile_path, birthday, deathday, adult, known_for_department } = response; |     const { | ||||||
|  |       id, | ||||||
|  |       name, | ||||||
|  |       profile_path, | ||||||
|  |       birthday, | ||||||
|  |       deathday, | ||||||
|  |       adult, | ||||||
|  |       place_of_birth, | ||||||
|  |       biography, | ||||||
|  |       known_for_department | ||||||
|  |     } = response; | ||||||
|  |  | ||||||
|     const birthDay = new Date(birthday) |     const birthDay = new Date(birthday); | ||||||
|     const deathDay = deathday ? new Date(deathday) : null |     const deathDay = deathday ? new Date(deathday) : null; | ||||||
|  |  | ||||||
|     return new Person(id, name, profile_path, birthDay, deathDay, adult, known_for_department) |     return new Person( | ||||||
|  |       id, | ||||||
|  |       name, | ||||||
|  |       profile_path, | ||||||
|  |       birthDay, | ||||||
|  |       deathDay, | ||||||
|  |       adult, | ||||||
|  |       place_of_birth, | ||||||
|  |       biography, | ||||||
|  |       known_for_department | ||||||
|  |     ); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   createJsonResponse() { |   createJsonResponse() { | ||||||
| @@ -27,10 +58,12 @@ class Person { | |||||||
|       poster: this.poster, |       poster: this.poster, | ||||||
|       birthday: this.birthday, |       birthday: this.birthday, | ||||||
|       deathday: this.deathday, |       deathday: this.deathday, | ||||||
|  |       place_of_birth: this.placeOfBirth, | ||||||
|  |       biography: this.biography, | ||||||
|       known_for_department: this.knownForDepartment, |       known_for_department: this.knownForDepartment, | ||||||
|       adult: this.adult, |       adult: this.adult, | ||||||
|       type: this.type |       type: this.type | ||||||
|     } |     }; | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -36,25 +36,28 @@ router.use(reqTokenToUser); | |||||||
| // TODO: Should have a separate middleware/router for handling headers. | // TODO: Should have a separate middleware/router for handling headers. | ||||||
| router.use((req, res, next) => { | router.use((req, res, next) => { | ||||||
|   // TODO add logging of all incoming |   // TODO add logging of all incoming | ||||||
|   const origin = req.headers.origin; |   // const origin = req.headers.origin; | ||||||
|   if (allowedOrigins.indexOf(origin) > -1) { |   // if (allowedOrigins.indexOf(origin) > -1) { | ||||||
|     res.setHeader("Access-Control-Allow-Origin", origin); |   //   res.setHeader("Access-Control-Allow-Origin", origin); | ||||||
|   } |   // } | ||||||
|  |  | ||||||
|   res.header( |   res.header( | ||||||
|     "Access-Control-Allow-Headers", |     "Access-Control-Allow-Headers", | ||||||
|     "Content-Type, Authorization, loggedinuser" |     "Content-Type, Authorization, loggedinuser, set-cookie" | ||||||
|   ); |   ); | ||||||
|   res.header("Access-Control-Allow-Methods", "POST, GET, PUT"); |  | ||||||
|  |   res.header("Access-Control-Allow-Credentials", "true"); | ||||||
|  |   res.header("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS"); | ||||||
|  |  | ||||||
|   next(); |   next(); | ||||||
| }); | }); | ||||||
|  |  | ||||||
| router.get("/", function mainHandler(req, res) { | router.get("/", (req, res) => { | ||||||
|   throw new Error("Broke!"); |   res.send("welcome to seasoned api"); | ||||||
| }); | }); | ||||||
|  |  | ||||||
| app.use(Raven.errorHandler()); | app.use(Raven.errorHandler()); | ||||||
| app.use(function onError(err, req, res, next) { | app.use((err, req, res, next) => { | ||||||
|   res.statusCode = 500; |   res.statusCode = 500; | ||||||
|   res.end(res.sentry + "\n"); |   res.end(res.sentry + "\n"); | ||||||
| }); | }); | ||||||
| @@ -142,20 +145,23 @@ router.get("/v2/movie/now_playing", listController.nowPlayingMovies); | |||||||
| router.get("/v2/movie/popular", listController.popularMovies); | router.get("/v2/movie/popular", listController.popularMovies); | ||||||
| router.get("/v2/movie/top_rated", listController.topRatedMovies); | router.get("/v2/movie/top_rated", listController.topRatedMovies); | ||||||
| router.get("/v2/movie/upcoming", listController.upcomingMovies); | router.get("/v2/movie/upcoming", listController.upcomingMovies); | ||||||
|  |  | ||||||
| router.get("/v2/show/now_playing", listController.nowPlayingShows); |  | ||||||
| router.get("/v2/show/popular", listController.popularShows); |  | ||||||
| router.get("/v2/show/top_rated", listController.topRatedShows); |  | ||||||
|  |  | ||||||
| router.get("/v2/movie/:id/credits", require("./controllers/movie/credits.js")); | router.get("/v2/movie/:id/credits", require("./controllers/movie/credits.js")); | ||||||
| router.get( | router.get( | ||||||
|   "/v2/movie/:id/release_dates", |   "/v2/movie/:id/release_dates", | ||||||
|   require("./controllers/movie/releaseDates.js") |   require("./controllers/movie/releaseDates.js") | ||||||
| ); | ); | ||||||
| router.get("/v2/show/:id/credits", require("./controllers/show/credits.js")); |  | ||||||
|  |  | ||||||
| router.get("/v2/movie/:id", require("./controllers/movie/info.js")); | router.get("/v2/movie/:id", require("./controllers/movie/info.js")); | ||||||
|  |  | ||||||
|  | router.get("/v2/show/now_playing", listController.nowPlayingShows); | ||||||
|  | router.get("/v2/show/popular", listController.popularShows); | ||||||
|  | router.get("/v2/show/top_rated", listController.topRatedShows); | ||||||
|  | router.get("/v2/show/:id/credits", require("./controllers/show/credits.js")); | ||||||
| router.get("/v2/show/:id", require("./controllers/show/info.js")); | router.get("/v2/show/:id", require("./controllers/show/info.js")); | ||||||
|  |  | ||||||
|  | router.get( | ||||||
|  |   "/v2/person/:id/credits", | ||||||
|  |   require("./controllers/person/credits.js") | ||||||
|  | ); | ||||||
| router.get("/v2/person/:id", require("./controllers/person/info.js")); | router.get("/v2/person/:id", require("./controllers/person/info.js")); | ||||||
|  |  | ||||||
| /** | /** | ||||||
|   | |||||||
							
								
								
									
										26
									
								
								seasoned_api/src/webserver/controllers/person/credits.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								seasoned_api/src/webserver/controllers/person/credits.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | |||||||
|  | const configuration = require("src/config/configuration").getInstance(); | ||||||
|  | const TMDB = require("src/tmdb/tmdb"); | ||||||
|  | const tmdb = new TMDB(configuration.get("tmdb", "apiKey")); | ||||||
|  |  | ||||||
|  | const personCreditsController = (req, res) => { | ||||||
|  |   const personId = req.params.id; | ||||||
|  |  | ||||||
|  |   return tmdb | ||||||
|  |     .personCredits(personId) | ||||||
|  |     .then(credits => res.send(credits)) | ||||||
|  |     .catch(error => { | ||||||
|  |       const { status, message } = error; | ||||||
|  |  | ||||||
|  |       if (status && message) { | ||||||
|  |         res.status(status).send({ success: false, message }); | ||||||
|  |       } else { | ||||||
|  |         // TODO log unhandled errors | ||||||
|  |         console.log("caugth show credits controller error", error); | ||||||
|  |         res.status(500).send({ | ||||||
|  |           message: "An unexpected error occured while requesting person credits" | ||||||
|  |         }); | ||||||
|  |       } | ||||||
|  |     }); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | module.exports = personCreditsController; | ||||||
| @@ -1,6 +1,19 @@ | |||||||
| const configuration = require('src/config/configuration').getInstance(); | const configuration = require("src/config/configuration").getInstance(); | ||||||
| const TMDB = require('src/tmdb/tmdb'); | const TMDB = require("src/tmdb/tmdb"); | ||||||
| const tmdb = new TMDB(configuration.get('tmdb', 'apiKey')); | const tmdb = new TMDB(configuration.get("tmdb", "apiKey")); | ||||||
|  |  | ||||||
|  | function handleError(error, res) { | ||||||
|  |   const { status, message } = error; | ||||||
|  |  | ||||||
|  |   if (status && message) { | ||||||
|  |     res.status(status).send({ success: false, message }); | ||||||
|  |   } else { | ||||||
|  |     console.log("caught personinfo controller error", error); | ||||||
|  |     res.status(500).send({ | ||||||
|  |       message: "An unexpected error occured while requesting person info." | ||||||
|  |     }); | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Controller: Retrieve information for a person |  * Controller: Retrieve information for a person | ||||||
| @@ -9,15 +22,28 @@ const tmdb = new TMDB(configuration.get('tmdb', 'apiKey')); | |||||||
|  * @returns {Callback} |  * @returns {Callback} | ||||||
|  */ |  */ | ||||||
|  |  | ||||||
| function personInfoController(req, res) { | async function personInfoController(req, res) { | ||||||
|   const personId = req.params.id; |   const personId = req.params.id; | ||||||
|  |   let { credits } = req.query; | ||||||
|  |   arguments; | ||||||
|  |  | ||||||
|  |   credits && credits.toLowerCase() === "true" | ||||||
|  |     ? (credits = true) | ||||||
|  |     : (credits = false); | ||||||
|  |  | ||||||
|   tmdb.personInfo(personId) |   let tmdbQueue = [tmdb.personInfo(personId)]; | ||||||
|   .then(person => res.send(person.createJsonResponse())) |   if (credits) tmdbQueue.push(tmdb.personCredits(personId)); | ||||||
|   .catch(error => { |  | ||||||
|     res.status(404).send({ success: false, message: error.message }); |   try { | ||||||
|   }); |     const [Person, Credits] = await Promise.all(tmdbQueue); | ||||||
|  |  | ||||||
|  |     const person = Person.createJsonResponse(); | ||||||
|  |     if (credits) person.credits = Credits.createJsonResponse(); | ||||||
|  |  | ||||||
|  |     return res.send(person); | ||||||
|  |   } catch (error) { | ||||||
|  |     handleError(error, res); | ||||||
|  |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| module.exports = personInfoController; | module.exports = personInfoController; | ||||||
|   | |||||||
| @@ -3,6 +3,7 @@ const TMDB = require("src/tmdb/tmdb"); | |||||||
| const RequestRepository = require("src/request/request"); | const RequestRepository = require("src/request/request"); | ||||||
| const tmdb = new TMDB(configuration.get("tmdb", "apiKey")); | const tmdb = new TMDB(configuration.get("tmdb", "apiKey")); | ||||||
| const request = new RequestRepository(); | const request = new RequestRepository(); | ||||||
|  | // const { sendSMS } = require("src/notifications/sms"); | ||||||
|  |  | ||||||
| const tmdbMovieInfo = id => { | const tmdbMovieInfo = id => { | ||||||
|   return tmdb.movieInfo(id); |   return tmdb.movieInfo(id); | ||||||
| @@ -47,9 +48,14 @@ function requestTmdbIdController(req, res) { | |||||||
|  |  | ||||||
|   mediaFunction(id) |   mediaFunction(id) | ||||||
|     // .catch((error) => { console.error(error); res.status(404).send({ success: false, error: 'Id not found' }) }) |     // .catch((error) => { console.error(error); res.status(404).send({ success: false, error: 'Id not found' }) }) | ||||||
|     .then(tmdbMedia => |     .then(tmdbMedia => { | ||||||
|       request.requestFromTmdb(tmdbMedia, ip, user_agent, username) |       request.requestFromTmdb(tmdbMedia, ip, user_agent, username); | ||||||
|     ) |  | ||||||
|  |       // TODO enable SMS | ||||||
|  |       // const url = `https://request.movie?${tmdbMedia.type}=${tmdbMedia.id}`; | ||||||
|  |       // const message = `${tmdbMedia.title} (${tmdbMedia.year}) requested!\n${url}`; | ||||||
|  |       // sendSMS(message); | ||||||
|  |     }) | ||||||
|     .then(() => |     .then(() => | ||||||
|       res.send({ success: true, message: "Request has been submitted." }) |       res.send({ success: true, message: "Request has been submitted." }) | ||||||
|     ) |     ) | ||||||
|   | |||||||
| @@ -11,15 +11,16 @@ const searchHistory = new SearchHistory(); | |||||||
|  * @returns {Callback} |  * @returns {Callback} | ||||||
|  */ |  */ | ||||||
| function movieSearchController(req, res) { | function movieSearchController(req, res) { | ||||||
|   const { query, page } = req.query; |   const { query, page, adult } = req.query; | ||||||
|   const username = req.loggedInUser ? req.loggedInUser.username : null; |   const username = req.loggedInUser ? req.loggedInUser.username : null; | ||||||
|  |   const includeAdult = adult == "true" ? true : false; | ||||||
|  |  | ||||||
|   if (username) { |   if (username) { | ||||||
|     return searchHistory.create(username, query); |     searchHistory.create(username, query); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   tmdb |   return tmdb | ||||||
|     .movieSearch(query, page) |     .movieSearch(query, page, includeAdult) | ||||||
|     .then(movieSearchResults => res.send(movieSearchResults)) |     .then(movieSearchResults => res.send(movieSearchResults)) | ||||||
|     .catch(error => { |     .catch(error => { | ||||||
|       const { status, message } = error; |       const { status, message } = error; | ||||||
|   | |||||||
| @@ -11,18 +11,17 @@ const searchHistory = new SearchHistory(); | |||||||
|  * @returns {Callback} |  * @returns {Callback} | ||||||
|  */ |  */ | ||||||
| function personSearchController(req, res) { | function personSearchController(req, res) { | ||||||
|   const { query, page } = req.query; |   const { query, page, adult } = req.query; | ||||||
|   const username = req.loggedInUser ? req.loggedInUser.username : null; |   const username = req.loggedInUser ? req.loggedInUser.username : null; | ||||||
|  |   const includeAdult = adult == "true" ? true : false; | ||||||
|  |  | ||||||
|   if (username) { |   if (username) { | ||||||
|     return searchHistory.create(username, query); |     searchHistory.create(username, query); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   tmdb |   return tmdb | ||||||
|     .personSearch(query, page) |     .personSearch(query, page, includeAdult) | ||||||
|     .then(person => { |     .then(persons => res.send(persons)) | ||||||
|       res.send(person); |  | ||||||
|     }) |  | ||||||
|     .catch(error => { |     .catch(error => { | ||||||
|       const { status, message } = error; |       const { status, message } = error; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -11,17 +11,16 @@ const searchHistory = new SearchHistory(); | |||||||
|  * @returns {Callback} |  * @returns {Callback} | ||||||
|  */ |  */ | ||||||
| function showSearchController(req, res) { | function showSearchController(req, res) { | ||||||
|   const { query, page } = req.query; |   const { query, page, adult } = req.query; | ||||||
|   const username = req.loggedInUser ? req.loggedInUser.username : null; |   const username = req.loggedInUser ? req.loggedInUser.username : null; | ||||||
|  |   const includeAdult = adult == "true" ? true : false; | ||||||
|  |  | ||||||
|   Promise.resolve() |  | ||||||
|     .then(() => { |  | ||||||
|   if (username) { |   if (username) { | ||||||
|         return searchHistory.create(username, query); |     searchHistory.create(username, query); | ||||||
|   } |   } | ||||||
|       return null; |  | ||||||
|     }) |   return tmdb | ||||||
|     .then(() => tmdb.showSearch(query, page)) |     .showSearch(query, page, includeAdult) | ||||||
|     .then(shows => { |     .then(shows => { | ||||||
|       res.send(shows); |       res.send(shows); | ||||||
|     }) |     }) | ||||||
|   | |||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
		Reference in New Issue
	
	Block a user