Update episode.js

This commit is contained in:
2025-05-27 19:39:16 +05:00
committed by GitHub
parent f16908d630
commit 38b574dbbb

View File

@@ -1,46 +1,28 @@
const axios = require('axios'); const axios = require('axios');
const fs = require('fs');
const path = require('path');
const loginList = JSON.parse( // Функция для запроса к Anixart API
fs.readFileSync(path.join(__dirname, 'login.json'), 'utf8')
);
// Получить логин по токену
async function getLoginFromToken(token) {
try {
const response = await axios.get(`https://api.anixart.tv/profile/preference/login/info?token=${token}`);
return response.data.login;
} catch (error) {
console.error("Ошибка при получении логина по токену:", error.message);
return null;
}
}
// Главная функция получения эпизода
async function getEpisodeFromAnixart(releaseId, token = '') { async function getEpisodeFromAnixart(releaseId, token = '') {
const login = token ? await getLoginFromToken(token) : null;
const allowedLogins = loginList.map(u => u.login);
// Проверка доступа
if (!login || !allowedLogins.includes(login)) {
return getAccessDeniedResponse();
}
const url = `https://api.anixart.tv/episode/${releaseId}${token ? `?token=${token}` : ''}`; const url = `https://api.anixart.tv/episode/${releaseId}${token ? `?token=${token}` : ''}`;
try { try {
const response = await axios.get(url); const response = await axios.get(url);
const data = response.data; const data = response.data;
// Изменение структуры поля `workers`
data.types = data.types.map((type) => ({ data.types = data.types.map((type) => ({
...type, ...type,
// id: 0,
workers: "источник: seele.su", workers: "источник: seele.su",
// name: "Недоступно (⁠≧⁠▽⁠≦⁠)",
// icon: null,
// view_count: null,
// pinned: false,
// episodes_count: null,
})); }));
// Если список `types` пуст, обращаемся к Seele API
if (data.code === 1 || data.types.length === 0) { if (data.code === 1 || data.types.length === 0) {
return await getEpisodeFromSeele(releaseId, token); return await getEpisodeFromSeele(releaseId, token);
} }
return data; return data;
} catch (error) { } catch (error) {
console.error("Ошибка при запросе к Anixart API:", error.message); console.error("Ошибка при запросе к Anixart API:", error.message);
@@ -48,48 +30,19 @@ async function getEpisodeFromAnixart(releaseId, token = '') {
} }
} }
// Ответ если нет доступа // Функция для запроса к Seele API
function getAccessDeniedResponse() {
return {
code: 0,
types: [
{
"@id": 1,
id: 1,
name: "Для просмотра требуется Anixart EX",
icon: "https://cloud.seele.su/images/seele.jpg",
workers: "Купить доступ: @seele_off",
is_sub: false,
episodes_count: 0,
view_count: 0,
pinned: false
},
{
"@id": 2,
id: 2,
name: "Не забудьте подписаться на наш Telegram-канал!",
icon: "https://cloud.seele.su/images/seele.jpg",
workers: "ТГК: @seele_channel",
is_sub: false,
episodes_count: 0,
view_count: 0,
pinned: false
}
]
};
}
// Seele fallback
async function getEpisodeFromSeele(releaseId, token = '') { async function getEpisodeFromSeele(releaseId, token = '') {
const url = `https://cloud.seele.su/episode/${releaseId}.json${token ? `?token=${token}` : ''}`; const url = `https://cloud.seele.su/episode/${releaseId}.json${token ? `?token=${token}` : ''}`;
try { try {
const response = await axios.get(url); const response = await axios.get(url);
const data = response.data; const data = response.data;
// Проверяем наличие `types`, если пусто - возвращаем кастомный ответ
if (!data.types || data.types.length === 0) { if (!data.types || data.types.length === 0) {
return getCustomNotFoundResponse(); return getCustomNotFoundResponse();
} }
// Изменение структуры поля `workers`
data.types = data.types.map((type) => ({ data.types = data.types.map((type) => ({
...type, ...type,
workers: "источник: seele.su", workers: "источник: seele.su",
@@ -97,6 +50,7 @@ async function getEpisodeFromSeele(releaseId, token = '') {
return data; return data;
} catch (error) { } catch (error) {
// Если ошибка - 404, возвращаем кастомный ответ
if (error.response && error.response.status === 404) { if (error.response && error.response.status === 404) {
return getCustomNotFoundResponse(); return getCustomNotFoundResponse();
} }
@@ -105,31 +59,32 @@ async function getEpisodeFromSeele(releaseId, token = '') {
} }
} }
// Функция для создания кастомного JSON-ответа
function getCustomNotFoundResponse() { function getCustomNotFoundResponse() {
return { return {
code: 0, "code": 0,
types: [ "types": [
{ {
"@id": 1, "@id": 1,
id: 1, "id": 1,
name: "К сожалению, это аниме недоступно!", "name": "К сожалению, это аниме недоступно!",
icon: "https://cloud.seele.su/images/seele.jpg", "icon": "https://cloud.seele.su/images/seele.jpg",
workers: "Это аниме полностью удалено с сервера anixart, либо его там не было изначально.", "workers": "Это аниме полностью удалено с сервера anixart, либо его там не было изначально.",
is_sub: false, "is_sub": false,
episodes_count: 0, "episodes_count": 0,
view_count: 0, "view_count": 0,
pinned: false "pinned": false
}, },
{ {
"@id": 2, "@id": 2,
id: 2, "id": 2,
name: "Не забудьте подписаться на наш Telegram-канал", "name": "Не забудьте подписаться на наш Telegram-канал 😊",
icon: "https://cloud.seele.su/images/seele.jpg", "icon": "https://cloud.seele.su/images/seele.jpg",
workers: "ТГК: @seele_channel", "workers": "Тгк: @seele_channel",
is_sub: false, "is_sub": false,
episodes_count: 0, "episodes_count": 0,
view_count: 0, "view_count": 0,
pinned: false "pinned": false
} }
] ]
}; };