diff --git a/server/api/themoviedb.ts b/server/api/themoviedb.ts index f86ae0629..354ff0ffd 100644 --- a/server/api/themoviedb.ts +++ b/server/api/themoviedb.ts @@ -91,11 +91,11 @@ interface TmdbSearchMultiResponse extends TmdbPaginatedResponse { results: (TmdbMovieResult | TmdbTvResult | TmdbPersonResult)[]; } -interface TmdbDiscoverMovieResponse extends TmdbPaginatedResponse { +interface TmdbSearchMovieResponse extends TmdbPaginatedResponse { results: TmdbMovieResult[]; } -interface TmdbDiscoverTvResponse extends TmdbPaginatedResponse { +interface TmdbSearchTvResponse extends TmdbPaginatedResponse { results: TmdbTvResult[]; } @@ -289,9 +289,9 @@ class TheMovieDb { page = 1, includeAdult = false, language = 'en-US', - }: DiscoverMovieOptions = {}): Promise => { + }: DiscoverMovieOptions = {}): Promise => { try { - const response = await this.axios.get( + const response = await this.axios.get( '/discover/movie', { params: { @@ -313,9 +313,9 @@ class TheMovieDb { sortBy = 'popularity.desc', page = 1, language = 'en-US', - }: DiscoverTvOptions = {}): Promise => { + }: DiscoverTvOptions = {}): Promise => { try { - const response = await this.axios.get( + const response = await this.axios.get( '/discover/tv', { params: { @@ -331,6 +331,72 @@ class TheMovieDb { throw new Error(`[TMDB] Failed to fetch discover tv: ${e.message}`); } }; + + public getAllTrending = async ({ + page = 1, + timeWindow = 'day', + }: { page?: number; timeWindow?: 'day' | 'week' } = {}): Promise< + TmdbSearchMultiResponse + > => { + try { + const response = await this.axios.get( + `/trending/all/${timeWindow}`, + { + params: { + page, + }, + } + ); + + return response.data; + } catch (e) { + throw new Error(`[TMDB] Failed to fetch all trending: ${e.message}`); + } + }; + + public getMovieTrending = async ({ + page = 1, + timeWindow = 'day', + }: { page?: number; timeWindow?: 'day' | 'week' } = {}): Promise< + TmdbSearchMovieResponse + > => { + try { + const response = await this.axios.get( + `/trending/movie/${timeWindow}`, + { + params: { + page, + }, + } + ); + + return response.data; + } catch (e) { + throw new Error(`[TMDB] Failed to fetch all trending: ${e.message}`); + } + }; + + public getTvTrending = async ({ + page = 1, + timeWindow = 'day', + }: { page?: number; timeWindow?: 'day' | 'week' } = {}): Promise< + TmdbSearchTvResponse + > => { + try { + const response = await this.axios.get( + `/trending/tv/${timeWindow}`, + { + params: { + page, + }, + } + ); + + return response.data; + } catch (e) { + throw new Error(`[TMDB] Failed to fetch all trending: ${e.message}`); + } + }; } export default TheMovieDb;