Update [releaseId].ts
This commit is contained in:
@@ -3,37 +3,33 @@ import axios from 'axios';
|
|||||||
|
|
||||||
interface EpisodeResponse {
|
interface EpisodeResponse {
|
||||||
code: number;
|
code: number;
|
||||||
sources?: Array<{
|
types?: Array<{
|
||||||
'@id': number;
|
'@id': number;
|
||||||
id: number;
|
id: number;
|
||||||
type: {
|
|
||||||
'@id': number;
|
|
||||||
id: number;
|
|
||||||
name: string;
|
|
||||||
icon: string | null;
|
|
||||||
workers: string;
|
|
||||||
is_sub: boolean;
|
|
||||||
episodes_count: number;
|
|
||||||
view_count: number;
|
|
||||||
pinned: boolean;
|
|
||||||
};
|
|
||||||
name: string;
|
name: string;
|
||||||
|
icon: string | null;
|
||||||
|
workers: string | null;
|
||||||
|
is_sub: boolean;
|
||||||
episodes_count: number;
|
episodes_count: number;
|
||||||
|
view_count: number;
|
||||||
|
pinned: boolean;
|
||||||
}>;
|
}>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
const { releaseId, typeId } = req.query;
|
const { releaseId } = req.query;
|
||||||
const anixartAPI = `https://api.anixart.tv/episode/${releaseId}/${typeId}`;
|
const anixartAPI = `https://api.anixart.tv/episode/${releaseId}`;
|
||||||
const seeleAPI = `https://seeleme.github.io/anixart/extension/api/${releaseId}/${typeId}.json`;
|
const seeleAPI = `https://seeleme.github.io/anixart/extension/api/episode/${releaseId}.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 (anixartResData.code === 0 && (!anixartResData.sources || anixartResData.sources.length === 0)) {
|
if (!modifyedData.types || modifyedData.types.length === 0) {
|
||||||
const seeleRes = await axios.get<EpisodeResponse>(seeleAPI);
|
const seeleRes = await axios.get(seeleAPI);
|
||||||
res.json({ is_blocked: true, ...seeleRes.data });
|
|
||||||
|
res.json({ is_blocked: true, ...modifyData(seeleRes.data) });
|
||||||
} else {
|
} else {
|
||||||
res.json(anixartResData);
|
res.json(anixartResData);
|
||||||
}
|
}
|
||||||
@@ -42,3 +38,16 @@ 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