Skip to content

Commit

Permalink
feat(TMDB): Add /trending endpoint (#580)
Browse files Browse the repository at this point in the history
* Add /trending path to TMDB

---------

Co-authored-by: Marouane <[email protected]>
  • Loading branch information
Babyyoda777 and riimuru authored Mar 23, 2024
1 parent 404f425 commit f4613b3
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/routes/meta/tmdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,28 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
reply.status(200).send(res);
});

fastify.get('/trending', async (request: FastifyRequest, reply: FastifyReply) => {
const validTimePeriods = new Set(['day', 'week'] as const);
type validTimeType = typeof validTimePeriods extends Set<infer T> ? T : undefined

const type = (request.query as { type?: string }).type || 'all';
let timePeriod = (request.query as { timePeriod?: validTimeType }).timePeriod || 'day';

// make day as default time period
if (!validTimePeriods.has(timePeriod)) timePeriod = 'day';

const page = (request.query as { page?: number }).page || 1;

const tmdb = new META.TMDB(tmdbApi);

try {
const res = await tmdb.fetchTrending(type, timePeriod, page);
reply.status(200).send(res);
} catch (err) {
reply.status(500).send({ message: 'Failed to fetch trending media.' });
}
});

fastify.get(
'/watch/:episodeId',
async (request: FastifyRequest, reply: FastifyReply) => {
Expand Down

0 comments on commit f4613b3

Please sign in to comment.