From f5de178203f1f13d0aaeb597f9c1e22b081da26a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=BC=E3=83=BC=E3=83=AC?= Date: Sun, 13 Oct 2024 18:29:41 +0500 Subject: [PATCH] Update [releaseId].ts --- .../api/extension/episode/[releaseId].ts | 43 +++++++++++++------ 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/src/pages/api/extension/episode/[releaseId].ts b/src/pages/api/extension/episode/[releaseId].ts index aee348a..8743564 100644 --- a/src/pages/api/extension/episode/[releaseId].ts +++ b/src/pages/api/extension/episode/[releaseId].ts @@ -23,31 +23,48 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) try { const anixartRes = await axios.get(anixartAPI); - const anixartResData = anixartRes.data; - const modifyedData = modifyData(anixartRes.data); + let modifyedData = modifyData(anixartRes.data); if (!modifyedData.types || modifyedData.types.length === 0) { - const seeleRes = await axios.get(seeleAPI); + const seeleRes = await axios.get(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 { - res.json(anixartResData); + return res.json(modifyedData); } } 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' }); } } function modifyData(data: EpisodeResponse): EpisodeResponse { if (data.types && data.types.length) { - data.types = data.types.map(type => { - return { - ...type, - workers: 'источник: seele.su (元一S2)' // Изменение значения workers на 'MD Sele' - } - }); + data.types = data.types.map(type => ({ + ...type, + workers: 'источник: seele.su (元一S2)' // Изменение значения workers + })); } - return data; }