Skip to content

Commit

Permalink
feat(gogoanime): get direct download links from download url (#598)
Browse files Browse the repository at this point in the history
  • Loading branch information
hase0278 authored Apr 24, 2024
1 parent f6cd4ef commit 31ad982
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/routes/anime/gogoanime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
'/popular',
'/recent-episodes',
'/anime-list',
'/download',
],
documentation: 'https://docs.consumet.org/#tag/gogoanime',
});
Expand Down Expand Up @@ -269,6 +270,30 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
}
},
);

fastify.get('/download', async (request: FastifyRequest, reply: FastifyReply) => {
try {
const downloadLink = (request.query as { link: string }).link;
if(!downloadLink){
reply.status(400).send('Invalid link');
}
const res = redis ? await cache.fetch(
redis as Redis,
`${redisPrefix}download-${downloadLink}`,
async () => await gogoanime
.fetchDirectDownloadLink(downloadLink)
.catch((err) => reply.status(404).send({ message: err })),
redisCacheTime * 24,
) : await gogoanime
.fetchDirectDownloadLink(downloadLink, process.env.RECAPTCHATOKEN ?? '')
.catch((err) => reply.status(404).send({ message: err }));
reply.status(200).send(res);
} catch {
reply
.status(500)
.send({ message: 'Something went wrong. Please try again later.' });
}
});
};

export default routes;

0 comments on commit 31ad982

Please sign in to comment.