Skip to content

Commit

Permalink
Merge pull request #4 from consumet/main
Browse files Browse the repository at this point in the history
feat(gogoanime): get direct download links from download url (consumet#598)
  • Loading branch information
VISHWAJ33T authored Apr 28, 2024
2 parents 9364406 + 31ad982 commit 7f46e6e
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 7f46e6e

Please sign in to comment.