Skip to content

Commit

Permalink
fix+feat(anix.sh): Added type variable to recently-uploaded, watch an…
Browse files Browse the repository at this point in the history
…d servers, added servers-type to fetch SUB, DUB, etc., added some error handling
  • Loading branch information
Shikiiii committed Jan 13, 2025
1 parent 84ca3d5 commit bb68438
Showing 1 changed file with 58 additions and 9 deletions.
67 changes: 58 additions & 9 deletions src/routes/anime/anix.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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();
Expand All @@ -8,7 +9,7 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
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'],
routes: ['/:query', '/recent-episodes', '/info/:id', '/watch/:id/:episodeId', '/servers/:id/:episodeId', '/servers-type/:id/:episodeId'],
documentation: 'https://docs.consumet.org/#tag/anix',
});
});
Expand All @@ -26,10 +27,16 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
'/recent-episodes',
async (request: FastifyRequest, reply: FastifyReply) => {
const { page = 1 } = request.query as { page?: number };

const type = (request.query as { type?: number }).type;

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

let res;
if (typeof type === 'undefined') {
res = await anix.fetchRecentEpisodes(page);
} else {
res = await anix.fetchRecentEpisodes(page, type);
}

reply.status(200).send(res);
} catch (err) {
console.error(err);
Expand Down Expand Up @@ -60,11 +67,20 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
'/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 };
const server = (request.query as { server: string }).server as StreamingServers;
const type = (request.query as { type: string }).type ?? 'sub';

try {
const res = await anix.fetchEpisodeSources(id, episodeId, server);
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) {
console.error(err);
Expand All @@ -80,9 +96,17 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
async (request: FastifyRequest, reply: FastifyReply) => {
const { id, episodeId } = request.params as { id: string; episodeId: string };

try {
const res = await anix.fetchEpisodeServers(id, 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) {
console.error(err);
Expand All @@ -92,6 +116,31 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
}
},
);

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

0 comments on commit bb68438

Please sign in to comment.