Update [releaseId].ts
This commit is contained in:
@@ -22,15 +22,18 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||||||
const seeleAPI = `https://cloud.seele.su/episode/${releaseId}.json`;
|
const seeleAPI = `https://cloud.seele.su/episode/${releaseId}.json`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Попробуем получить данные от Anixart
|
||||||
const anixartRes = await axios.get<EpisodeResponse>(anixartAPI);
|
const anixartRes = await axios.get<EpisodeResponse>(anixartAPI);
|
||||||
let modifyedData = modifyData(anixartRes.data);
|
let modifyedData = modifyData(anixartRes.data);
|
||||||
|
|
||||||
|
// Если данных нет, переходим к Seele API
|
||||||
if (!modifyedData.types || modifyedData.types.length === 0) {
|
if (!modifyedData.types || modifyedData.types.length === 0) {
|
||||||
|
try {
|
||||||
const seeleRes = await axios.get<EpisodeResponse>(seeleAPI);
|
const seeleRes = await axios.get<EpisodeResponse>(seeleAPI);
|
||||||
modifyedData = modifyData(seeleRes.data);
|
modifyedData = modifyData(seeleRes.data);
|
||||||
|
|
||||||
|
// Если и Seele API не вернула данных, возвращаем кастомный ответ
|
||||||
if (!modifyedData.types || modifyedData.types.length === 0) {
|
if (!modifyedData.types || modifyedData.types.length === 0) {
|
||||||
// Если ни Anixart, ни Seele API не вернули данные
|
|
||||||
return res.json({
|
return res.json({
|
||||||
code: 0,
|
code: 0,
|
||||||
types: [
|
types: [
|
||||||
@@ -39,7 +42,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||||||
id: 1,
|
id: 1,
|
||||||
name: 'Это аниме недоступно!',
|
name: 'Это аниме недоступно!',
|
||||||
icon: null,
|
icon: null,
|
||||||
workers: 'Это аниме было полностью удалено серверов Anixart или изначально не было там.',
|
workers: 'Это аниме было полностью удалено с серверов anixart или вообще не было там изначально!',
|
||||||
is_sub: false,
|
is_sub: false,
|
||||||
episodes_count: 0,
|
episodes_count: 0,
|
||||||
view_count: 0,
|
view_count: 0,
|
||||||
@@ -50,12 +53,16 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||||||
} else {
|
} else {
|
||||||
return res.json({ is_blocked: true, ...modifyedData });
|
return res.json({ is_blocked: true, ...modifyedData });
|
||||||
}
|
}
|
||||||
|
} catch (seeleError) {
|
||||||
|
console.error('Error fetching data from Seele API:', seeleError);
|
||||||
|
return res.status(500).json({ message: 'Error fetching data from Seele API' });
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return res.json(modifyedData);
|
return res.json(modifyedData);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (anixartError) {
|
||||||
console.error('Error fetching data from Anixart or Seele API:', error);
|
console.error('Error fetching data from Anixart API:', anixartError);
|
||||||
res.status(500).json({ message: 'Internal Server Error' });
|
return res.status(500).json({ message: 'Error fetching data from Anixart API' });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user