Skip to content

Commit c2cdbad

Browse files
committed
fix: post-filter rating check was gated behind blockUnrated flag
Critical bug: postFilterDiscoverMovies and postFilterDiscoverTv had an early return that only ran the rating post-filter when blockUnrated was enabled. Routes like /trending that lack TMDB certification.lte pre-filter rely entirely on post-filtering, so R-rated movies and TV-MA shows passed through unfiltered when a user had a max rating set but blockUnrated was false. Fixes: postFilterDiscoverMovies runs when maxMovieRating OR blockUnrated is set. postFilterDiscoverTv runs when maxTvRating OR blockUnrated is set. filterMovieBatch and filterTvBatch use actual limits.blockUnrated instead of hardcoded true.
1 parent 3b64d9e commit c2cdbad

1 file changed

Lines changed: 21 additions & 22 deletions

File tree

server/routes/discover.ts

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import type {
99
import type { UserContentRatingLimits } from '@server/constants/contentRatings';
1010
import {
1111
MOVIE_RATINGS,
12+
UNRATED_VALUES,
1213
shouldFilterMovie,
1314
shouldFilterTv,
14-
UNRATED_VALUES,
1515
type MovieRating,
1616
} from '@server/constants/contentRatings';
1717
import { MediaType } from '@server/constants/media';
@@ -45,15 +45,15 @@ export const createTmdbWithRegionLanguage = (user?: User): TheMovieDb => {
4545
user?.settings?.streamingRegion === 'all'
4646
? ''
4747
: user?.settings?.streamingRegion
48-
? user?.settings?.streamingRegion
49-
: settings.main.discoverRegion;
48+
? user?.settings?.streamingRegion
49+
: settings.main.discoverRegion;
5050

5151
const originalLanguage =
5252
user?.settings?.originalLanguage === 'all'
5353
? ''
5454
: user?.settings?.originalLanguage
55-
? user?.settings?.originalLanguage
56-
: settings.main.originalLanguage;
55+
? user?.settings?.originalLanguage
56+
: settings.main.originalLanguage;
5757

5858
return new TheMovieDb({
5959
discoverRegion,
@@ -213,7 +213,7 @@ const filterMovieBatch = async (
213213
for (const outcome of settled) {
214214
if (outcome.status !== 'fulfilled') continue;
215215
const { movie, cert, title } = outcome.value;
216-
if (!shouldFilterMovie(cert, limits.maxMovieRating, true)) {
216+
if (!shouldFilterMovie(cert, limits.maxMovieRating, limits.blockUnrated)) {
217217
filtered.push(movie);
218218
} else {
219219
logger.debug('Blocked movie by rating (post-filter)', {
@@ -239,7 +239,7 @@ const postFilterDiscoverMovies = async (
239239
? results.filter((movie) => !movie.adult)
240240
: results;
241241

242-
if (!limits.blockUnrated) return filtered;
242+
if (!limits.blockUnrated && !limits.maxMovieRating) return filtered;
243243

244244
filtered = await filterMovieBatch(filtered, tmdb, limits);
245245

@@ -277,7 +277,7 @@ const filterTvBatch = async (
277277
for (const outcome of settled) {
278278
if (outcome.status !== 'fulfilled') continue;
279279
const { show, cert, title } = outcome.value;
280-
if (!shouldFilterTv(cert, limits.maxTvRating, true)) {
280+
if (!shouldFilterTv(cert, limits.maxTvRating, limits.blockUnrated)) {
281281
filtered.push(show);
282282
} else {
283283
logger.debug('Blocked TV show by rating (post-filter)', {
@@ -298,7 +298,7 @@ const postFilterDiscoverTv = async (
298298
limits: UserContentRatingLimits,
299299
fetchNextPage?: () => Promise<TmdbTvResult[] | null>
300300
): Promise<TmdbTvResult[]> => {
301-
if (!limits.blockUnrated) return results;
301+
if (!limits.blockUnrated && !limits.maxTvRating) return results;
302302

303303
const filtered = await filterTvBatch(results, tmdb, limits);
304304

@@ -858,9 +858,8 @@ discoverRoutes.get('/tv', async (req, res, next) => {
858858
ratingLimits,
859859
tvPage < data.total_pages
860860
? async () =>
861-
(
862-
await tmdb.getDiscoverTv({ page: tvPage + 1, ...tvDiscoverOpts })
863-
).results
861+
(await tmdb.getDiscoverTv({ page: tvPage + 1, ...tvDiscoverOpts }))
862+
.results
864863
: undefined
865864
);
866865

@@ -1294,16 +1293,16 @@ discoverRoutes.get('/trending', async (req, res, next) => {
12941293
)
12951294
)
12961295
: isPerson(result)
1297-
? mapPersonResult(result)
1298-
: isCollection(result)
1299-
? mapCollectionResult(result)
1300-
: mapTvResult(
1301-
result,
1302-
media.find(
1303-
(med) =>
1304-
med.tmdbId === result.id && med.mediaType === MediaType.TV
1305-
)
1306-
)
1296+
? mapPersonResult(result)
1297+
: isCollection(result)
1298+
? mapCollectionResult(result)
1299+
: mapTvResult(
1300+
result,
1301+
media.find(
1302+
(med) =>
1303+
med.tmdbId === result.id && med.mediaType === MediaType.TV
1304+
)
1305+
)
13071306
),
13081307
});
13091308
} catch (e) {

0 commit comments

Comments
 (0)