Files
anixart-extension/api/v1/index.js
2025-05-23 14:17:02 +05:00

76 lines
2.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const express = require('express');
// Новые методы
const getVerifiedUsers = require('./src/is_verified');
const getRolesUsers = require('./src/is_roles');
const { getProfileFromAnixart } = require('./src/profile');
const { getEpisodeFromAnixart } = require('./src/episode');
const getToggles = require('./src/toggles');
const app = express();
const PORT = 3000;
// Новый эндпоинт: Роли пользователей
app.get('/api/v2/is_roles', (req, res) => {
try {
const data = getRolesUsers();
res.status(200).json(data);
} catch {
res.status(200).json([]);
}
});
// Новый эндпоинт: Верифицированные пользователи
app.get('/api/v2/is_verified', (req, res) => {
try {
const data = getVerifiedUsers();
res.status(200).json(data);
} catch {
res.status(200).json([]);
}
});
// Новый эндпоинт: Профиль пользователя
app.get('/api/v2/profile/:profileId', async (req, res) => {
const { profileId } = req.params;
const { token } = req.query;
try {
const data = await getProfileFromAnixart(profileId, token);
res.json(data);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
// Новый эндпоинт: Информация об эпизоде
app.get('/api/v2/episode/:releaseId', async (req, res) => {
const { releaseId } = req.params;
const { token } = req.query;
try {
const data = await getEpisodeFromAnixart(releaseId, token);
res.json(data);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
// Новый эндпоинт: Конфигурационный JSON
app.get('/api/v2/config/toggles', async (req, res) => {
try {
const toggles = await getToggles();
res.json(toggles);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
// Обработчик для неизвестных маршрутов
app.use((req, res) => {
res.status(404).json({ error: "Страница не существует!", status: 404 });
});
// Запуск сервера
app.listen(PORT, () => {
console.log(`Сервер запущен на http://localhost:${PORT}`);
});