From 5c60ffc567df3500f9435603a15fd10fa3e038f8 Mon Sep 17 00:00:00 2001 From: Joseph Risk Date: Tue, 9 Jan 2024 21:03:11 -0600 Subject: [PATCH] fix: api language query parameter (#3720) --- server/routes/collection.ts | 2 +- server/routes/discover.ts | 28 ++++++++++++++-------------- server/routes/index.ts | 4 ++-- server/routes/movie.ts | 6 +++--- server/routes/person.ts | 4 ++-- server/routes/search.ts | 4 ++-- server/routes/tv.ts | 8 ++++---- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/server/routes/collection.ts b/server/routes/collection.ts index d58b0357d..3cece5e33 100644 --- a/server/routes/collection.ts +++ b/server/routes/collection.ts @@ -12,7 +12,7 @@ collectionRoutes.get<{ id: string }>('/:id', async (req, res, next) => { try { const collection = await tmdb.getCollection({ collectionId: Number(req.params.id), - language: req.locale ?? (req.query.language as string), + language: (req.query.language as string) ?? req.locale, }); const media = await Media.getRelatedMedia( diff --git a/server/routes/discover.ts b/server/routes/discover.ts index 487d1a329..b35306446 100644 --- a/server/routes/discover.ts +++ b/server/routes/discover.ts @@ -164,7 +164,7 @@ discoverRoutes.get<{ language: string }>( const data = await tmdb.getDiscoverMovies({ page: Number(req.query.page), - language: req.locale ?? (req.query.language as string), + language: (req.query.language as string) ?? req.locale, originalLanguage: req.params.language, }); @@ -208,7 +208,7 @@ discoverRoutes.get<{ genreId: string }>( try { const genres = await tmdb.getMovieGenres({ - language: req.locale ?? (req.query.language as string), + language: (req.query.language as string) ?? req.locale, }); const genre = genres.find( @@ -221,7 +221,7 @@ discoverRoutes.get<{ genreId: string }>( const data = await tmdb.getDiscoverMovies({ page: Number(req.query.page), - language: req.locale ?? (req.query.language as string), + language: (req.query.language as string) ?? req.locale, genre: req.params.genreId as string, }); @@ -268,7 +268,7 @@ discoverRoutes.get<{ studioId: string }>( const data = await tmdb.getDiscoverMovies({ page: Number(req.query.page), - language: req.locale ?? (req.query.language as string), + language: (req.query.language as string) ?? req.locale, studio: req.params.studioId as string, }); @@ -317,7 +317,7 @@ discoverRoutes.get('/movies/upcoming', async (req, res, next) => { try { const data = await tmdb.getDiscoverMovies({ page: Number(req.query.page), - language: req.locale ?? (req.query.language as string), + language: (req.query.language as string) ?? req.locale, primaryReleaseDateGte: date, }); @@ -440,7 +440,7 @@ discoverRoutes.get<{ language: string }>( const data = await tmdb.getDiscoverTv({ page: Number(req.query.page), - language: req.locale ?? (req.query.language as string), + language: (req.query.language as string) ?? req.locale, originalLanguage: req.params.language, }); @@ -484,7 +484,7 @@ discoverRoutes.get<{ genreId: string }>( try { const genres = await tmdb.getTvGenres({ - language: req.locale ?? (req.query.language as string), + language: (req.query.language as string) ?? req.locale, }); const genre = genres.find( @@ -497,7 +497,7 @@ discoverRoutes.get<{ genreId: string }>( const data = await tmdb.getDiscoverTv({ page: Number(req.query.page), - language: req.locale ?? (req.query.language as string), + language: (req.query.language as string) ?? req.locale, genre: req.params.genreId, }); @@ -544,7 +544,7 @@ discoverRoutes.get<{ networkId: string }>( const data = await tmdb.getDiscoverTv({ page: Number(req.query.page), - language: req.locale ?? (req.query.language as string), + language: (req.query.language as string) ?? req.locale, network: Number(req.params.networkId), }); @@ -593,7 +593,7 @@ discoverRoutes.get('/tv/upcoming', async (req, res, next) => { try { const data = await tmdb.getDiscoverTv({ page: Number(req.query.page), - language: req.locale ?? (req.query.language as string), + language: (req.query.language as string) ?? req.locale, firstAirDateGte: date, }); @@ -632,7 +632,7 @@ discoverRoutes.get('/trending', async (req, res, next) => { try { const data = await tmdb.getAllTrending({ page: Number(req.query.page), - language: req.locale ?? (req.query.language as string), + language: (req.query.language as string) ?? req.locale, }); const media = await Media.getRelatedMedia( @@ -686,7 +686,7 @@ discoverRoutes.get<{ keywordId: string }>( const data = await tmdb.getMoviesByKeyword({ keywordId: Number(req.params.keywordId), page: Number(req.query.page), - language: req.locale ?? (req.query.language as string), + language: (req.query.language as string) ?? req.locale, }); const media = await Media.getRelatedMedia( @@ -730,7 +730,7 @@ discoverRoutes.get<{ language: string }, GenreSliderItem[]>( const mappedGenres: GenreSliderItem[] = []; const genres = await tmdb.getMovieGenres({ - language: req.locale ?? (req.query.language as string), + language: (req.query.language as string) ?? req.locale, }); await Promise.all( @@ -774,7 +774,7 @@ discoverRoutes.get<{ language: string }, GenreSliderItem[]>( const mappedGenres: GenreSliderItem[] = []; const genres = await tmdb.getTvGenres({ - language: req.locale ?? (req.query.language as string), + language: (req.query.language as string) ?? req.locale, }); await Promise.all( diff --git a/server/routes/index.ts b/server/routes/index.ts index 702b18d78..4ce2507cf 100644 --- a/server/routes/index.ts +++ b/server/routes/index.ts @@ -235,7 +235,7 @@ router.get('/genres/movie', isAuthenticated(), async (req, res, next) => { try { const genres = await tmdb.getMovieGenres({ - language: req.locale ?? (req.query.language as string), + language: (req.query.language as string) ?? req.locale, }); return res.status(200).json(genres); @@ -256,7 +256,7 @@ router.get('/genres/tv', isAuthenticated(), async (req, res, next) => { try { const genres = await tmdb.getTvGenres({ - language: req.locale ?? (req.query.language as string), + language: (req.query.language as string) ?? req.locale, }); return res.status(200).json(genres); diff --git a/server/routes/movie.ts b/server/routes/movie.ts index e39e2e86e..a1eeafcc4 100644 --- a/server/routes/movie.ts +++ b/server/routes/movie.ts @@ -17,7 +17,7 @@ movieRoutes.get('/:id', async (req, res, next) => { try { const tmdbMovie = await tmdb.getMovie({ movieId: Number(req.params.id), - language: req.locale ?? (req.query.language as string), + language: (req.query.language as string) ?? req.locale, }); const media = await Media.getMedia(tmdbMovie.id, MediaType.MOVIE); @@ -43,7 +43,7 @@ movieRoutes.get('/:id/recommendations', async (req, res, next) => { const results = await tmdb.getMovieRecommendations({ movieId: Number(req.params.id), page: Number(req.query.page), - language: req.locale ?? (req.query.language as string), + language: (req.query.language as string) ?? req.locale, }); const media = await Media.getRelatedMedia( @@ -84,7 +84,7 @@ movieRoutes.get('/:id/similar', async (req, res, next) => { const results = await tmdb.getMovieSimilar({ movieId: Number(req.params.id), page: Number(req.query.page), - language: req.locale ?? (req.query.language as string), + language: (req.query.language as string) ?? req.locale, }); const media = await Media.getRelatedMedia( diff --git a/server/routes/person.ts b/server/routes/person.ts index 7f5d62236..0bb59691d 100644 --- a/server/routes/person.ts +++ b/server/routes/person.ts @@ -16,7 +16,7 @@ personRoutes.get('/:id', async (req, res, next) => { try { const person = await tmdb.getPerson({ personId: Number(req.params.id), - language: req.locale ?? (req.query.language as string), + language: (req.query.language as string) ?? req.locale, }); return res.status(200).json(mapPersonDetails(person)); } catch (e) { @@ -38,7 +38,7 @@ personRoutes.get('/:id/combined_credits', async (req, res, next) => { try { const combinedCredits = await tmdb.getPersonCombinedCredits({ personId: Number(req.params.id), - language: req.locale ?? (req.query.language as string), + language: (req.query.language as string) ?? req.locale, }); const castMedia = await Media.getRelatedMedia( diff --git a/server/routes/search.ts b/server/routes/search.ts index b9254221a..55a8aa6ee 100644 --- a/server/routes/search.ts +++ b/server/routes/search.ts @@ -20,7 +20,7 @@ searchRoutes.get('/', async (req, res, next) => { .match(searchProvider.pattern) as RegExpMatchArray; results = await searchProvider.search({ id, - language: req.locale ?? (req.query.language as string), + language: (req.query.language as string) ?? req.locale, query: queryString, }); } else { @@ -29,7 +29,7 @@ searchRoutes.get('/', async (req, res, next) => { results = await tmdb.searchMulti({ query: queryString, page: Number(req.query.page), - language: req.locale ?? (req.query.language as string), + language: (req.query.language as string) ?? req.locale, }); } diff --git a/server/routes/tv.ts b/server/routes/tv.ts index 95c8dc11c..2061a3a30 100644 --- a/server/routes/tv.ts +++ b/server/routes/tv.ts @@ -14,7 +14,7 @@ tvRoutes.get('/:id', async (req, res, next) => { try { const tv = await tmdb.getTvShow({ tvId: Number(req.params.id), - language: req.locale ?? (req.query.language as string), + language: (req.query.language as string) ?? req.locale, }); const media = await Media.getMedia(tv.id, MediaType.TV); @@ -40,7 +40,7 @@ tvRoutes.get('/:id/season/:seasonNumber', async (req, res, next) => { const season = await tmdb.getTvSeason({ tvId: Number(req.params.id), seasonNumber: Number(req.params.seasonNumber), - language: req.locale ?? (req.query.language as string), + language: (req.query.language as string) ?? req.locale, }); return res.status(200).json(mapSeasonWithEpisodes(season)); @@ -65,7 +65,7 @@ tvRoutes.get('/:id/recommendations', async (req, res, next) => { const results = await tmdb.getTvRecommendations({ tvId: Number(req.params.id), page: Number(req.query.page), - language: req.locale ?? (req.query.language as string), + language: (req.query.language as string) ?? req.locale, }); const media = await Media.getRelatedMedia( @@ -105,7 +105,7 @@ tvRoutes.get('/:id/similar', async (req, res, next) => { const results = await tmdb.getTvSimilar({ tvId: Number(req.params.id), page: Number(req.query.page), - language: req.locale ?? (req.query.language as string), + language: (req.query.language as string) ?? req.locale, }); const media = await Media.getRelatedMedia(