Skip to content

Commit

Permalink
feat(anilist + dramacool): Add routes for fetching staff information …
Browse files Browse the repository at this point in the history
…& popular drama (#628)
  • Loading branch information
2004durgesh authored Aug 6, 2024
1 parent 6c7484f commit f589eef
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/routes/meta/anilist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
12 changes: 12 additions & 0 deletions src/routes/movies/dramacool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit f589eef

Please sign in to comment.