forked from consumet/api.consumet.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
anix.ts
128 lines (102 loc) · 4.3 KB
/
anix.ts
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import { FastifyRequest, FastifyReply, FastifyInstance, RegisterOptions } from 'fastify';
import { ANIME } from '@consumet/extensions';
import { StreamingServers } from '@consumet/extensions/dist/models';
const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
const anix = new ANIME.Anix();
fastify.get('/', (_, rp) => {
rp.status(200).send({
intro:
"Welcome to the anix provider: check out the provider's website @ https://anix.sh/",
routes: ['/:query', '/info/:id', '/watch/:episodeId'],
documentation: 'https://docs.consumet.org/#tag/anix',
});
});
fastify.get(
'/recent-episodes',
async (request: FastifyRequest, reply: FastifyReply) => {
const page = (request.query as { page: number }).page;
const type = (request.query as { type: number }).type;
console.log(page, type);
reply.status(200).send(await anix.fetchRecentEpisodes(page, type));
},
);
fastify.get('/search', async (request: FastifyRequest, reply: FastifyReply) => {
const query = (request.query as { query: string }).query;
const page = (request.query as { page: number }).page ?? 1;
const res = await anix.search(query, page);
reply.status(200).send(res);
});
fastify.get('/info', async (request: FastifyRequest, reply: FastifyReply) => {
const id = (request.query as { id: string }).id;
if (typeof id === 'undefined')
return reply.status(400).send({ message: 'id is required' });
try {
const res = await anix
.fetchAnimeInfo(id)
.catch((err) => reply.status(404).send({ message: err }));
reply.status(200).send(res);
} catch (err) {
reply
.status(500)
.send({ message: 'Something went wrong. Contact developer for help.' });
}
});
fastify.get('/watch', async (request: FastifyRequest, reply: FastifyReply) => {
const id = (request.query as { id: string }).id;
const episodeId = (request.query as { episodeId: string }).episodeId;
const type = (request.query as { type: string }).type ?? 'sub';
const server = (request.query as { server: string }).server as StreamingServers;
if (typeof id === 'undefined')
return reply.status(400).send({ message: 'id is required' });
if (typeof episodeId === 'undefined')
return reply.status(400).send({ message: 'episodeId is required' });
try {
const res = await anix
.fetchEpisodeSources(id, episodeId, server, type)
.catch((err) => reply.status(404).send({ message: err }));
reply.status(200).send(res);
} catch (err) {
reply
.status(500)
.send({ message: 'Something went wrong. Contact developer for help.' });
}
});
fastify.get('/servers', async (request: FastifyRequest, reply: FastifyReply) => {
const id = (request.query as { id: string }).id;
const episodeId = (request.query as { episodeId: string }).episodeId;
if (typeof id === 'undefined')
return reply.status(400).send({ message: 'id is required' });
if (typeof episodeId === 'undefined')
return reply.status(400).send({ message: 'episodeId is required' });
try {
const res = await anix
.fetchEpisodeServers(id, episodeId)
.catch((err) => reply.status(404).send({ message: err }));
reply.status(200).send(res);
} catch (err) {
reply
.status(500)
.send({ message: 'Something went wrong. Contact developer for help.' });
}
});
fastify.get('/servers-type', async (request: FastifyRequest, reply: FastifyReply) => {
const id = (request.query as { id: string }).id;
const episodeId = (request.query as { episodeId: string }).episodeId;
const type = (request.query as { type: string }).type ?? 'sub';
if (typeof id === 'undefined')
return reply.status(400).send({ message: 'id is required' });
if (typeof episodeId === 'undefined')
return reply.status(400).send({ message: 'episodeId is required' });
try {
const res = await anix
.fetchEpisodeServerType(id, episodeId, type)
.catch((err) => reply.status(404).send({ message: err }));
reply.status(200).send(res);
} catch (err) {
reply
.status(500)
.send({ message: 'Something went wrong. Contact developer for help.' });
}
});
};
export default routes;