Skip to content

Commit

Permalink
feat(Anix): Added Anix.ts from Consumet.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Shikiiii committed Dec 14, 2024
1 parent 2060a7d commit 2bcc716
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
97 changes: 97 additions & 0 deletions src/routes/anime/anix.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { FastifyRequest, FastifyReply, FastifyInstance, RegisterOptions } from 'fastify';
import { ANIME } from '@consumet/extensions';

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', '/recent-episodes', '/info/:id', '/watch/:id/:episodeId', '/servers/:id/:episodeId'],
documentation: 'https://docs.consumet.org/#tag/anix',
});
});

fastify.get('/:query', async (request: FastifyRequest, reply: FastifyReply) => {
const query = (request.params as { query: string }).query;
const { page = 1 } = request.query as { page?: number };

const res = await anix.search(query, page);

reply.status(200).send(res);
});

fastify.get(
'/recent-episodes',
async (request: FastifyRequest, reply: FastifyReply) => {
const { page = 1 } = request.query as { page?: number };

try {
const res = await anix.fetchRecentEpisodes(page);

reply.status(200).send(res);
} catch (err) {
console.error(err);
reply
.status(500)
.send({ message: 'Something went wrong. Contact developer for help.' });
}
},
);

fastify.get('/info/:id', async (request: FastifyRequest, reply: FastifyReply) => {
const id = decodeURIComponent((request.params as { id: string }).id);

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/:id/:episodeId',
async (request: FastifyRequest, reply: FastifyReply) => {
const { id, episodeId } = request.params as { id: string; episodeId: string };
const { server } = request.query as { server?: string };

try {
const res = await anix.fetchEpisodeSources(id, episodeId, server);

reply.status(200).send(res);
} catch (err) {
console.error(err);
reply
.status(500)
.send({ message: 'Something went wrong. Contact developer for help.' });
}
},
);

fastify.get(
'/servers/:id/:episodeId',
async (request: FastifyRequest, reply: FastifyReply) => {
const { id, episodeId } = request.params as { id: string; episodeId: string };

try {
const res = await anix.fetchEpisodeServers(id, episodeId);

reply.status(200).send(res);
} catch (err) {
console.error(err);
reply
.status(500)
.send({ message: 'Something went wrong. Contact developer for help.' });
}
},
);
};

export default routes;
2 changes: 2 additions & 0 deletions src/routes/anime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import anify from './anify';
import crunchyroll from './crunchyroll';
import bilibili from './bilibili';
import marin from './marin';
import anix from './anix';

const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
await fastify.register(gogoanime, { prefix: '/gogoanime' });
Expand All @@ -21,6 +22,7 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
await fastify.register(crunchyroll, { prefix: '/crunchyroll' });
await fastify.register(bilibili, { prefix: '/bilibili' });
await fastify.register(marin, { prefix: '/marin' });
await fastify.register(anix, { prefix: '/anix' });

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

0 comments on commit 2bcc716

Please sign in to comment.