Skip to content

Commit 84ca3d5

Browse files
authored
feat(anix.sh) - Added anix.ts from consumet.ts (#650)
* Initial commit Created from https://vercel.com/new * feat(Anix): Added Anix.ts from Consumet.ts * Resolved merge conflicts * Missed README.md
1 parent 0522c2b commit 84ca3d5

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

src/routes/anime/anix.ts

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import { FastifyRequest, FastifyReply, FastifyInstance, RegisterOptions } from 'fastify';
2+
import { ANIME } from '@consumet/extensions';
3+
4+
const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
5+
const anix = new ANIME.Anix();
6+
7+
fastify.get('/', (_, rp) => {
8+
rp.status(200).send({
9+
intro:
10+
"Welcome to the Anix provider: check out the provider's website @ https://anix.sh",
11+
routes: ['/:query', '/recent-episodes', '/info/:id', '/watch/:id/:episodeId', '/servers/:id/:episodeId'],
12+
documentation: 'https://docs.consumet.org/#tag/anix',
13+
});
14+
});
15+
16+
fastify.get('/:query', async (request: FastifyRequest, reply: FastifyReply) => {
17+
const query = (request.params as { query: string }).query;
18+
const { page = 1 } = request.query as { page?: number };
19+
20+
const res = await anix.search(query, page);
21+
22+
reply.status(200).send(res);
23+
});
24+
25+
fastify.get(
26+
'/recent-episodes',
27+
async (request: FastifyRequest, reply: FastifyReply) => {
28+
const { page = 1 } = request.query as { page?: number };
29+
30+
try {
31+
const res = await anix.fetchRecentEpisodes(page);
32+
33+
reply.status(200).send(res);
34+
} catch (err) {
35+
console.error(err);
36+
reply
37+
.status(500)
38+
.send({ message: 'Something went wrong. Contact developer for help.' });
39+
}
40+
},
41+
);
42+
43+
fastify.get('/info/:id', async (request: FastifyRequest, reply: FastifyReply) => {
44+
const id = decodeURIComponent((request.params as { id: string }).id);
45+
46+
try {
47+
const res = await anix
48+
.fetchAnimeInfo(id)
49+
.catch((err) => reply.status(404).send({ message: err }));
50+
51+
reply.status(200).send(res);
52+
} catch (err) {
53+
reply
54+
.status(500)
55+
.send({ message: 'Something went wrong. Contact developer for help.' });
56+
}
57+
});
58+
59+
fastify.get(
60+
'/watch/:id/:episodeId',
61+
async (request: FastifyRequest, reply: FastifyReply) => {
62+
const { id, episodeId } = request.params as { id: string; episodeId: string };
63+
const { server } = request.query as { server?: string };
64+
65+
try {
66+
const res = await anix.fetchEpisodeSources(id, episodeId, server);
67+
68+
reply.status(200).send(res);
69+
} catch (err) {
70+
console.error(err);
71+
reply
72+
.status(500)
73+
.send({ message: 'Something went wrong. Contact developer for help.' });
74+
}
75+
},
76+
);
77+
78+
fastify.get(
79+
'/servers/:id/:episodeId',
80+
async (request: FastifyRequest, reply: FastifyReply) => {
81+
const { id, episodeId } = request.params as { id: string; episodeId: string };
82+
83+
try {
84+
const res = await anix.fetchEpisodeServers(id, episodeId);
85+
86+
reply.status(200).send(res);
87+
} catch (err) {
88+
console.error(err);
89+
reply
90+
.status(500)
91+
.send({ message: 'Something went wrong. Contact developer for help.' });
92+
}
93+
},
94+
);
95+
};
96+
97+
export default routes;

src/routes/anime/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import anify from './anify';
1010
import crunchyroll from './crunchyroll';
1111
import bilibili from './bilibili';
1212
import marin from './marin';
13+
import anix from './anix';
1314

1415
const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
1516
await fastify.register(gogoanime, { prefix: '/gogoanime' });
@@ -21,6 +22,7 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
2122
await fastify.register(crunchyroll, { prefix: '/crunchyroll' });
2223
await fastify.register(bilibili, { prefix: '/bilibili' });
2324
await fastify.register(marin, { prefix: '/marin' });
25+
await fastify.register(anix, { prefix: '/anix' });
2426

2527
fastify.get('/', async (request: any, reply: any) => {
2628
reply.status(200).send('Welcome to Consumet Anime 🗾');

src/routes/movies/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import fmovies from './fmovies';
88
import goku from './goku';
99
import movieshd from './movieshd';
1010
import sflix from './sflix';
11+
1112
const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
1213
await fastify.register(flixhq, { prefix: '/flixhq' });
1314
await fastify.register(viewasian, { prefix: '/viewasian' });
@@ -16,6 +17,7 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
1617
await fastify.register(goku, { prefix: '/goku' });
1718
await fastify.register(movieshd, { prefix: '/movieshd' });
1819
await fastify.register(sflix, { prefix: '/sflix' });
20+
1921
fastify.get('/', async (request: any, reply: any) => {
2022
reply.status(200).send('Welcome to Consumet Movies and TV Shows');
2123
});

0 commit comments

Comments
 (0)