Add files via upload
This commit is contained in:
53
src/pages/api/extension/episode/[releaseId].ts
Normal file
53
src/pages/api/extension/episode/[releaseId].ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { NextApiRequest, NextApiResponse } from 'next';
|
||||
import axios from 'axios';
|
||||
|
||||
interface EpisodeResponse {
|
||||
code: number;
|
||||
types?: Array<{
|
||||
'@id': number;
|
||||
id: number;
|
||||
name: string;
|
||||
icon: string | null;
|
||||
workers: string | null;
|
||||
is_sub: boolean;
|
||||
episodes_count: number;
|
||||
view_count: number;
|
||||
pinned: boolean;
|
||||
}>;
|
||||
}
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const { releaseId } = req.query;
|
||||
const anixartAPI = `https://api.anixart.tv/episode/${releaseId}`;
|
||||
const seeleAPI = `https://seele-off.github.io/anixart/extension/api/episode/${releaseId}.json`;
|
||||
|
||||
try {
|
||||
const anixartRes = await axios.get<EpisodeResponse>(anixartAPI);
|
||||
const anixartResData = anixartRes.data;
|
||||
const modifyedData = modifyData(anixartRes.data);
|
||||
|
||||
if (!modifyedData.types || modifyedData.types.length === 0) {
|
||||
const seeleRes = await axios.get(seeleAPI);
|
||||
|
||||
res.json({ is_blocked: true, ...modifyData(seeleRes.data) });
|
||||
} else {
|
||||
res.json(anixartResData);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching data from Anixart 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: 'Отображается благодаря расширению «MD Seele»' // Изменение значения workers на 'MD Sele'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
52
src/pages/api/extension/profile/[userId].ts
Normal file
52
src/pages/api/extension/profile/[userId].ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { NextApiRequest, NextApiResponse } from 'next';
|
||||
import axios from 'axios';
|
||||
|
||||
type Role = {
|
||||
id: number;
|
||||
name: string;
|
||||
color: string;
|
||||
}
|
||||
|
||||
type ProfileResponse = {
|
||||
code: number;
|
||||
profile?: {
|
||||
id: number;
|
||||
is_verified: boolean;
|
||||
is_sponsor: boolean;
|
||||
is_sponsor_transferred: boolean;
|
||||
sponsorshipExpires: number;
|
||||
roles: Array<Role>,
|
||||
// and other types
|
||||
}
|
||||
}
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const { userId } = req.query;
|
||||
const anixartAPI = `https://api.anixart.tv/profile/${userId}`;
|
||||
|
||||
try {
|
||||
const anixartRes = await axios.get<ProfileResponse>(anixartAPI);
|
||||
|
||||
const currentProfile = anixartRes.data.profile && userId === '790852'
|
||||
? {
|
||||
...anixartRes.data.profile,
|
||||
is_verified: true,
|
||||
is_sponsor: true,
|
||||
is_sponsor_transferred: false,
|
||||
sponsorshipExpires: Number.MAX_SAFE_INTEGER,
|
||||
roles: [
|
||||
{
|
||||
id: 1,
|
||||
name: "Разработчик мода",
|
||||
color: "F04E4E"
|
||||
}
|
||||
],
|
||||
}
|
||||
: anixartRes.data.profile;
|
||||
|
||||
res.json({ ...anixartRes.data, profile: currentProfile });
|
||||
} catch (error) {
|
||||
console.error('Error fetching data from Anixart API:', error);
|
||||
res.status(500).json({ message: 'Internal Server Error' });
|
||||
}
|
||||
}
|
||||
46
src/pages/api/extension/release/[id].ts
Normal file
46
src/pages/api/extension/release/[id].ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { NextApiRequest, NextApiResponse } from 'next';
|
||||
import axios from 'axios';
|
||||
|
||||
interface AnimeResponse {
|
||||
code: number;
|
||||
release: {
|
||||
title_original: string;
|
||||
grade: number;
|
||||
};
|
||||
// other types
|
||||
}
|
||||
|
||||
interface ShikiResponse {
|
||||
score: string;
|
||||
// other types
|
||||
}
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const { id } = req.query;
|
||||
const anixartAPI = `https://api.anixart.tv/release/${id}`;
|
||||
const shikimoriAPI = `https://shikimori.one/api/animes`;
|
||||
|
||||
try {
|
||||
const { data } = await axios.get<AnimeResponse>(anixartAPI);
|
||||
const shikiAnime = await axios.get<ShikiResponse[]>(
|
||||
`${shikimoriAPI}?search=${encodeURIComponent(data.release.title_original)}`
|
||||
);
|
||||
const shikiData = shikiAnime.data;
|
||||
|
||||
if (shikiData.length) {
|
||||
res.status(200).json({
|
||||
...data,
|
||||
release: {
|
||||
...data.release,
|
||||
grade: Number(shikiData[0].score),
|
||||
},
|
||||
});
|
||||
|
||||
} else {
|
||||
res.status(200).json(data);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching data from Anixart or Shikimori API:', error);
|
||||
res.status(500).json({ message: 'Internal Server Error' });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user