Skip to content

Commit

Permalink
feat(flixhq): Add country and genre routes (#581)
Browse files Browse the repository at this point in the history
  • Loading branch information
2004durgesh authored Mar 18, 2024
1 parent d49a669 commit 1bc5851
Showing 1 changed file with 83 additions and 39 deletions.
122 changes: 83 additions & 39 deletions src/routes/movies/flixhq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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;

0 comments on commit 1bc5851

Please sign in to comment.