Searching with adult parameter is now handled and also cached correctly.
This commit is contained in:
@@ -144,9 +144,9 @@ class TMDB {
|
|||||||
.then(person => Person.convertFromTmdbResponse(person))
|
.then(person => Person.convertFromTmdbResponse(person))
|
||||||
}
|
}
|
||||||
|
|
||||||
multiSearch(search_query, page=1) {
|
multiSearch(search_query, page=1, adult=true) {
|
||||||
const query = { query: search_query, page: page };
|
const query = { query: search_query, page: page, include_adult: adult };
|
||||||
const cacheKey = `tmdb/${this.cacheTags.multiSearch}:${page}:${search_query}`;
|
const cacheKey = `tmdb/${this.cacheTags.multiSearch}:${page}:${search_query}:${adult}`;
|
||||||
|
|
||||||
return this.getFromCacheOrFetchFromTmdb(cacheKey, 'searchMulti', query)
|
return this.getFromCacheOrFetchFromTmdb(cacheKey, 'searchMulti', query)
|
||||||
.then(response => this.cache.set(cacheKey, response, this.defaultTTL))
|
.then(response => this.cache.set(cacheKey, response, this.defaultTTL))
|
||||||
@@ -159,9 +159,9 @@ 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) {
|
movieSearch(query, page=1, adult=true) {
|
||||||
const tmdbquery = { query: query, page: page };
|
const tmdbquery = { query: query, page: page, adult: adult };
|
||||||
const cacheKey = `tmdb/${this.cacheTags.movieSearch}:${page}:${query}`;
|
const cacheKey = `tmdb/${this.cacheTags.movieSearch}:${page}:${query}:${adult}`;
|
||||||
|
|
||||||
return this.getFromCacheOrFetchFromTmdb(cacheKey, 'searchMovie', query)
|
return this.getFromCacheOrFetchFromTmdb(cacheKey, 'searchMovie', query)
|
||||||
.then(response => this.cache.set(cacheKey, response, this.defaultTTL))
|
.then(response => this.cache.set(cacheKey, response, this.defaultTTL))
|
||||||
@@ -192,7 +192,7 @@ class TMDB {
|
|||||||
personSearch(query, page=1) {
|
personSearch(query, page=1) {
|
||||||
|
|
||||||
const tmdbquery = { query: query, page: page, include_adult: true };
|
const tmdbquery = { query: query, page: page, include_adult: true };
|
||||||
const cacheKey = `tmdb/${this.cacheTags.personSearch}:${page}:${query}`;
|
const cacheKey = `tmdb/${this.cacheTags.personSearch}:${page}:${query}:${include_adult}`;
|
||||||
|
|
||||||
return this.getFromCacheOrFetchFromTmdb(cacheKey, 'searchPerson', query)
|
return this.getFromCacheOrFetchFromTmdb(cacheKey, 'searchPerson', query)
|
||||||
.then(response => this.cache.set(cacheKey, response, this.defaultTTL))
|
.then(response => this.cache.set(cacheKey, response, this.defaultTTL))
|
||||||
|
|||||||
@@ -19,13 +19,13 @@ function checkAndCreateJsonResponse(result) {
|
|||||||
*/
|
*/
|
||||||
function multiSearchController(req, res) {
|
function multiSearchController(req, res) {
|
||||||
const user = req.loggedInUser;
|
const user = req.loggedInUser;
|
||||||
const { query, page } = req.query;
|
const { query, page, adult } = req.query;
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
searchHistory.create(user.username, query)
|
searchHistory.create(user.username, query)
|
||||||
}
|
}
|
||||||
|
|
||||||
return tmdb.multiSearch(query, page)
|
return tmdb.multiSearch(query, page, adult)
|
||||||
.then(multiSearchResults => res.send(multiSearchResults))
|
.then(multiSearchResults => res.send(multiSearchResults))
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
const { status, message } = error;
|
const { status, message } = error;
|
||||||
|
|||||||
Reference in New Issue
Block a user