Update [releaseId].ts
This commit is contained in:
@@ -3,33 +3,37 @@ import axios from 'axios';
|
|||||||
|
|
||||||
interface EpisodeResponse {
|
interface EpisodeResponse {
|
||||||
code: number;
|
code: number;
|
||||||
types?: Array<{
|
sources?: Array<{
|
||||||
|
'@id': number;
|
||||||
|
id: number;
|
||||||
|
type: {
|
||||||
'@id': number;
|
'@id': number;
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
icon: string | null;
|
icon: string | null;
|
||||||
workers: string | null;
|
workers: string;
|
||||||
is_sub: boolean;
|
is_sub: boolean;
|
||||||
episodes_count: number;
|
episodes_count: number;
|
||||||
view_count: number;
|
view_count: number;
|
||||||
pinned: boolean;
|
pinned: boolean;
|
||||||
|
};
|
||||||
|
name: string;
|
||||||
|
episodes_count: number;
|
||||||
}>;
|
}>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
const { releaseId } = req.query;
|
const { releaseId, typeId } = req.query;
|
||||||
const anixartAPI = `https://api.anixart.tv/episode/${releaseId}`;
|
const anixartAPI = `https://api.anixart.tv/episode/${releaseId}/${typeId}`;
|
||||||
const seeleAPI = `https://seeleme.github.io/anixart/extension/api/episode/${releaseId}.json`;
|
const seeleAPI = `https://seeleme.github.io/anixart/extension/api/${releaseId}/${typeId}.json`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const anixartRes = await axios.get<EpisodeResponse>(anixartAPI);
|
const anixartRes = await axios.get<EpisodeResponse>(anixartAPI);
|
||||||
const anixartResData = anixartRes.data;
|
const anixartResData = anixartRes.data;
|
||||||
const modifyedData = modifyData(anixartRes.data);
|
|
||||||
|
|
||||||
if (!modifyedData.types || modifyedData.types.length === 0) {
|
if (anixartResData.code === 0 && (!anixartResData.sources || anixartResData.sources.length === 0)) {
|
||||||
const seeleRes = await axios.get(seeleAPI);
|
const seeleRes = await axios.get<EpisodeResponse>(seeleAPI);
|
||||||
|
res.json({ is_blocked: true, ...seeleRes.data });
|
||||||
res.json({ is_blocked: true, ...modifyData(seeleRes.data) });
|
|
||||||
} else {
|
} else {
|
||||||
res.json(anixartResData);
|
res.json(anixartResData);
|
||||||
}
|
}
|
||||||
@@ -38,16 +42,3 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||||||
res.status(500).json({ message: 'Internal Server Error' });
|
res.status(500).json({ message: 'Internal Server Error' });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function modifyData(data: EpisodeResponse): EpisodeResponse {
|
|
||||||
if (data.types && data.types.length) {
|
|
||||||
data.types = data.types.map(type => {
|
|
||||||
return {
|
|
||||||
...type,
|
|
||||||
workers: 'Отображается благодаря расширению «MD Seele»' // Изменение значения workers на 'MD Sele'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user