From f589eef9af9c042791bfcdb402c9a74215277ea4 Mon Sep 17 00:00:00 2001 From: 2004durgesh Date: Wed, 7 Aug 2024 00:12:13 +0530 Subject: [PATCH] feat(anilist + dramacool): Add routes for fetching staff information & popular drama (#628) --- src/routes/meta/anilist.ts | 23 +++++++++++++++++++++++ src/routes/movies/dramacool.ts | 12 ++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/routes/meta/anilist.ts b/src/routes/meta/anilist.ts index f5dac79a..b8d2081f 100644 --- a/src/routes/meta/anilist.ts +++ b/src/routes/meta/anilist.ts @@ -343,6 +343,29 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => { } }, ); + + //anilist staff info from character id (for example: voice actors) + //http://127.0.0.1:3000/meta/anilist/staff/95095 (gives info of sukuna's voice actor (Junichi Suwabe) ) + fastify.get("/staff/:id", async (request: FastifyRequest, reply: FastifyReply) => { + const id = (request.params as { id: string }).id; + + const anilist = generateAnilistMeta(); + try { + redis + ? reply.status(200).send( + await cache.fetch( + redis, + `anilist:staff;${id}`, + async () => await anilist.fetchStaffById(Number(id)), + 60 * 60, + ), + ) + : reply.status(200).send(await anilist.fetchStaffById(Number(id))); + + } catch (err: any) { + reply.status(404).send({ message: err.message }); + } + }); }; const generateAnilistMeta = (provider: string | undefined = undefined): Anilist => { diff --git a/src/routes/movies/dramacool.ts b/src/routes/movies/dramacool.ts index 4f8f602d..4d38ecc9 100644 --- a/src/routes/movies/dramacool.ts +++ b/src/routes/movies/dramacool.ts @@ -65,6 +65,18 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => { .send({ message: 'Something went wrong. Please try again later.' }); } }); + + fastify.get("/popular", async (request: FastifyRequest, reply: FastifyReply) => { + const page = (request.query as { page: number }).page; + try { + const res = await dramacool.fetchPopular(page ? page : 1); + reply.status(200).send(res); + } catch (err) { + reply + .status(500) + .send({ message: 'Something went wrong. Please try again later.' }); + } + }) }; export default routes;