feat: create route to return title information
Summary: Test Plan:
This commit is contained in:
76
src/controllers/title/amvstrm.ts
Normal file
76
src/controllers/title/amvstrm.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
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,
|
||||
}));
|
||||
}
|
||||
Reference in New Issue
Block a user