Skip to content

Commit 933c49c

Browse files
authored
fix+feat(anix.sh): Add type variable to recent-episodes, watch & servers (#655)
* fix+feat(anix.sh): Added type variable to recently-uploaded, watch and servers, added servers-type to fetch SUB, DUB, etc., added some error handling * fix(anix): Merged servers and servers-type into 1 endpoint servers
1 parent 84ca3d5 commit 933c49c

File tree

1 file changed

+40
-8
lines changed

1 file changed

+40
-8
lines changed

src/routes/anime/anix.ts

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { FastifyRequest, FastifyReply, FastifyInstance, RegisterOptions } from 'fastify';
22
import { ANIME } from '@consumet/extensions';
3+
import { StreamingServers } from '@consumet/extensions/dist/models';
34

45
const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
56
const anix = new ANIME.Anix();
@@ -26,10 +27,16 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
2627
'/recent-episodes',
2728
async (request: FastifyRequest, reply: FastifyReply) => {
2829
const { page = 1 } = request.query as { page?: number };
29-
30+
const type = (request.query as { type?: number }).type;
31+
3032
try {
31-
const res = await anix.fetchRecentEpisodes(page);
32-
33+
let res;
34+
if (typeof type === 'undefined') {
35+
res = await anix.fetchRecentEpisodes(page);
36+
} else {
37+
res = await anix.fetchRecentEpisodes(page, type);
38+
}
39+
3340
reply.status(200).send(res);
3441
} catch (err) {
3542
console.error(err);
@@ -60,11 +67,20 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
6067
'/watch/:id/:episodeId',
6168
async (request: FastifyRequest, reply: FastifyReply) => {
6269
const { id, episodeId } = request.params as { id: string; episodeId: string };
63-
const { server } = request.query as { server?: string };
70+
const server = (request.query as { server: string }).server as StreamingServers;
71+
const type = (request.query as { type: string }).type ?? 'sub';
6472

65-
try {
66-
const res = await anix.fetchEpisodeSources(id, episodeId, server);
73+
if (typeof id === 'undefined')
74+
return reply.status(400).send({ message: 'id is required' });
6775

76+
if (typeof episodeId === 'undefined')
77+
return reply.status(400).send({ message: 'episodeId is required' });
78+
79+
try {
80+
const res = await anix
81+
.fetchEpisodeSources(id, episodeId, server, type)
82+
.catch((err) => reply.status(404).send({ message: err }));
83+
6884
reply.status(200).send(res);
6985
} catch (err) {
7086
console.error(err);
@@ -79,10 +95,26 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
7995
'/servers/:id/:episodeId',
8096
async (request: FastifyRequest, reply: FastifyReply) => {
8197
const { id, episodeId } = request.params as { id: string; episodeId: string };
98+
const type = (request.query as { type?: string }).type;
8299

83-
try {
84-
const res = await anix.fetchEpisodeServers(id, episodeId);
100+
if (typeof id === 'undefined')
101+
return reply.status(400).send({ message: 'id is required' });
85102

103+
if (typeof episodeId === 'undefined')
104+
return reply.status(400).send({ message: 'episodeId is required' });
105+
106+
try {
107+
let res;
108+
if (typeof type === 'undefined') {
109+
res = await anix
110+
.fetchEpisodeServers(id, episodeId)
111+
.catch((err) => reply.status(404).send({ message: err }));;
112+
} else {
113+
res = await anix
114+
.fetchEpisodeServerType(id, episodeId, type)
115+
.catch((err) => reply.status(404).send({ message: err }));;
116+
}
117+
86118
reply.status(200).send(res);
87119
} catch (err) {
88120
console.error(err);

0 commit comments

Comments
 (0)