diff --git a/src/routes/movies/flixhq.ts b/src/routes/movies/flixhq.ts index adf1521d..4a1175d2 100644 --- a/src/routes/movies/flixhq.ts +++ b/src/routes/movies/flixhq.ts @@ -25,11 +25,11 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => { let res = redis ? await cache.fetch( - redis as Redis, - `flixhq:${query}:${page}`, - async () => await flixhq.search(query, page ? page : 1), - 60 * 60 * 6, - ) + redis as Redis, + `flixhq:${query}:${page}`, + async () => await flixhq.search(query, page ? page : 1), + 60 * 60 * 6, + ) : await flixhq.search(query, page ? page : 1); reply.status(200).send(res); @@ -38,11 +38,11 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => { fastify.get('/recent-shows', async (request: FastifyRequest, reply: FastifyReply) => { let res = redis ? await cache.fetch( - redis as Redis, - `flixhq:recent-shows`, - async () => await flixhq.fetchRecentTvShows(), - 60 * 60 * 3, - ) + redis as Redis, + `flixhq:recent-shows`, + async () => await flixhq.fetchRecentTvShows(), + 60 * 60 * 3, + ) : await flixhq.fetchRecentTvShows(); reply.status(200).send(res); @@ -51,11 +51,11 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => { fastify.get('/recent-movies', async (request: FastifyRequest, reply: FastifyReply) => { let res = redis ? await cache.fetch( - redis as Redis, - `flixhq:recent-movies`, - async () => await flixhq.fetchRecentMovies(), - 60 * 60 * 3, - ) + redis as Redis, + `flixhq:recent-movies`, + async () => await flixhq.fetchRecentMovies(), + 60 * 60 * 3, + ) : await flixhq.fetchRecentMovies(); reply.status(200).send(res); @@ -76,14 +76,14 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => { let res = redis ? await cache.fetch( - redis as Redis, - `flixhq:trending:${type}`, - async () => - type === 'tv' - ? await flixhq.fetchTrendingTvShows() - : await flixhq.fetchTrendingMovies(), - 60 * 60 * 3, - ) + redis as Redis, + `flixhq:trending:${type}`, + async () => + type === 'tv' + ? await flixhq.fetchTrendingTvShows() + : await flixhq.fetchTrendingMovies(), + 60 * 60 * 3, + ) : type === 'tv' ? await flixhq.fetchTrendingTvShows() : await flixhq.fetchTrendingMovies(); @@ -108,11 +108,11 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => { try { let res = redis ? await cache.fetch( - redis as Redis, - `flixhq:info:${id}`, - async () => await flixhq.fetchMediaInfo(id), - 60 * 60 * 3, - ) + redis as Redis, + `flixhq:info:${id}`, + async () => await flixhq.fetchMediaInfo(id), + 60 * 60 * 3, + ) : await flixhq.fetchMediaInfo(id); reply.status(200).send(res); @@ -140,11 +140,11 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => { try { let res = redis ? await cache.fetch( - redis as Redis, - `flixhq:watch:${episodeId}:${mediaId}:${server}`, - async () => await flixhq.fetchEpisodeSources(episodeId, mediaId, server), - 60 * 30, - ) + redis as Redis, + `flixhq:watch:${episodeId}:${mediaId}:${server}`, + async () => await flixhq.fetchEpisodeSources(episodeId, mediaId, server), + 60 * 30, + ) : await flixhq.fetchEpisodeSources(episodeId, mediaId, server); reply.status(200).send(res); @@ -161,11 +161,11 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => { try { let res = redis ? await cache.fetch( - redis as Redis, - `flixhq:servers:${episodeId}:${mediaId}`, - async () => await flixhq.fetchEpisodeServers(episodeId, mediaId), - 60 * 30, - ) + redis as Redis, + `flixhq:servers:${episodeId}:${mediaId}`, + async () => await flixhq.fetchEpisodeServers(episodeId, mediaId), + 60 * 30, + ) : await flixhq.fetchEpisodeServers(episodeId, mediaId); reply.status(200).send(res); @@ -176,6 +176,50 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => { }); } }); -}; + fastify.get('/country/:country', async (request: FastifyRequest, reply: FastifyReply) => { + const country = (request.params as { country: string }).country; + const page = (request.query as { page: number }).page ?? 1; + try { + let res = redis + ? await cache.fetch( + redis as Redis, + `flixhq:country:${country}:${page}`, + async () => await flixhq.fetchByCountry(country, page), + 60 * 60 * 3, + ) + : await flixhq.fetchByCountry(country, page); + + reply.status(200).send(res); + } catch (error) { + reply.status(500).send({ + message: + 'Something went wrong. Please try again later. or contact the developers.', + }); + } + }); + + +fastify.get('/genre/:genre', async (request: FastifyRequest, reply: FastifyReply) => { + const genre = (request.params as { genre: string }).genre; + const page = (request.query as { page: number }).page ?? 1; + try { + let res = redis + ? await cache.fetch( + redis as Redis, + `flixhq:genre:${genre}:${page}`, + async () => await flixhq.fetchByGenre(genre, page), + 60 * 60 * 3, + ) + : await flixhq.fetchByGenre(genre, page); + + reply.status(200).send(res); + } catch (error) { + reply.status(500).send({ + message: + 'Something went wrong. Please try again later. or contact the developers.', + }); + } +}); +}; export default routes;