Update [releaseId].ts

This commit is contained in:
2024-09-01 21:36:08 +05:00
committed by GitHub
parent c19c20b009
commit f59eba8581

View File

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