77 lines
1.9 KiB
TypeScript
77 lines
1.9 KiB
TypeScript
import { Title } from "~/types/title";
|
|
|
|
export async function fetchTitleFromAmvstrm(
|
|
aniListId: number,
|
|
): Promise<Title | undefined> {
|
|
return Promise.all([
|
|
fetch(`https://api-amvstrm.nyt92.eu.org/api/v2/info/${aniListId}`).then(
|
|
(res) => res.json() as Promise<any>,
|
|
),
|
|
fetchMissingInformationFromAnify(aniListId).catch((err) => {
|
|
console.error("Failed to get missing information from Anify", err);
|
|
return null;
|
|
}),
|
|
]).then(
|
|
async ([
|
|
{
|
|
id,
|
|
idMal,
|
|
title: { english: englishTitle, userPreferred: userPreferredTitle },
|
|
description,
|
|
episodes,
|
|
genres,
|
|
status,
|
|
bannerImage,
|
|
coverImage: {
|
|
extraLarge: extraLargeCoverImage,
|
|
large: largeCoverImage,
|
|
medium: mediumCoverImage,
|
|
},
|
|
countryOfOrigin,
|
|
nextair: nextAiringEpisode,
|
|
score: { averageScore },
|
|
},
|
|
anifyInfo,
|
|
]) => {
|
|
return {
|
|
id,
|
|
idMal,
|
|
title: {
|
|
userPreferred: userPreferredTitle,
|
|
english: englishTitle,
|
|
},
|
|
description,
|
|
episodes,
|
|
genres,
|
|
status,
|
|
averageScore,
|
|
bannerImage: bannerImage ?? anifyInfo?.bannerImage,
|
|
coverImage: {
|
|
extraLarge: extraLargeCoverImage,
|
|
large: largeCoverImage,
|
|
medium: mediumCoverImage,
|
|
},
|
|
countryOfOrigin: countryOfOrigin ?? anifyInfo?.countryOfOrigin,
|
|
nextAiringEpisode,
|
|
mediaListEntry: null,
|
|
};
|
|
},
|
|
);
|
|
}
|
|
|
|
type AnifyInformation = {
|
|
bannerImage: string | null;
|
|
countryOfOrigin: string;
|
|
};
|
|
|
|
function fetchMissingInformationFromAnify(
|
|
aniListId: number,
|
|
): Promise<AnifyInformation> {
|
|
return fetch(`https://api.anify.tv/info?id=${aniListId}`)
|
|
.then((res) => res.json() as Promise<AnifyInformation>)
|
|
.then(({ bannerImage, countryOfOrigin }) => ({
|
|
bannerImage,
|
|
countryOfOrigin,
|
|
}));
|
|
}
|