Update [releaseId].ts

This commit is contained in:
2024-10-13 19:22:07 +05:00
committed by GitHub
parent 0ec3c93736
commit 0819cd759f

View File

@@ -23,31 +23,48 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
try { try {
const anixartRes = await axios.get<EpisodeResponse>(anixartAPI); const anixartRes = await axios.get<EpisodeResponse>(anixartAPI);
const anixartResData = anixartRes.data; let modifyedData = modifyData(anixartRes.data);
const modifyedData = modifyData(anixartRes.data);
if (!modifyedData.types || modifyedData.types.length === 0) { if (!modifyedData.types || modifyedData.types.length === 0) {
const seeleRes = await axios.get(seeleAPI); const seeleRes = await axios.get<EpisodeResponse>(seeleAPI);
modifyedData = modifyData(seeleRes.data);
res.json({ is_blocked: true, ...modifyData(seeleRes.data) }); if (!modifyedData.types || modifyedData.types.length === 0) {
// Если ни Anixart, ни Seele API не вернули данные
return res.json({
code: 0,
types: [
{
'@id': 1,
id: 1,
name: 'Это аниме недоступно!',
icon: null,
workers: 'Это аниме было полностью удалено с серверов anixart или вообще не было там изначально!',
is_sub: false,
episodes_count: 0,
view_count: 0,
pinned: false
}
]
});
} else {
return res.json({ is_blocked: true, ...modifyedData });
}
} else { } else {
res.json(anixartResData); return res.json(modifyedData);
} }
} catch (error) { } catch (error) {
console.error('Error fetching data from Anixart API:', error); console.error('Error fetching data from Anixart or Seele API:', error);
res.status(500).json({ message: 'Internal Server Error' }); res.status(500).json({ message: 'Internal Server Error' });
} }
} }
function modifyData(data: EpisodeResponse): EpisodeResponse { function modifyData(data: EpisodeResponse): EpisodeResponse {
if (data.types && data.types.length) { if (data.types && data.types.length) {
data.types = data.types.map(type => { data.types = data.types.map(type => ({
return { ...type,
...type, workers: 'источник: seele.su (元一S2)' // Изменение значения workers
workers: 'источник: seele.su (元一S2)' // Изменение значения workers на 'MD Sele' }));
}
});
} }
return data; return data;
} }