..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60 | import { FastifyRequest, FastifyReply, FastifyInstance, RegisterOptions } from 'fastify';
import { MANGA } from '@consumet/extensions';
const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
const mangadex = new MANGA.MangaDex();
fastify.get('/', (_, rp) => {
rp.status(200).send({
intro:
"Welcome to the mangadex provider: check out the provider's website @ https://mangadex.org/",
routes: ['/:query', '/info/:id', '/read/:chapterId'],
documentation: 'https://docs.consumet.org/#tag/mangadex',
});
});
fastify.get('/:query', async (request: FastifyRequest, reply: FastifyReply) => {
const query = (request.params as { query: string }).query;
const page = (request.query as { page: number }).page;
const res = await mangadex.search(query, page);
reply.status(200).send(res);
});
fastify.get('/info/:id', async (request: FastifyRequest, reply: FastifyReply) => {
const id = decodeURIComponent((request.params as { id: string }).id);
try {
const res = await mangadex
.fetchMangaInfo(id)
.catch((err) => reply.status(404).send({ message: err }));
reply.status(200).send(res);
} catch (err) {
reply
.status(500)
.send({ message: 'Something went wrong. Please try again later.' });
}
});
fastify.get(
'/read/:chapterId',
async (request: FastifyRequest, reply: FastifyReply) => {
const chapterId = (request.params as { chapterId: string }).chapterId;
try {
const res = await mangadex.fetchChapterPages(chapterId);
reply.status(200).send(res);
} catch (err) {
reply
.status(500)
.send({ message: 'Something went wrong. Please try again later.' });
}
},
);
};
export default routes;
|
|