refactor: replace amvstrm source with aniwatch

This commit is contained in:
2024-08-18 21:37:13 -04:00
parent 0bcc547ede
commit 1a06eb51eb
14 changed files with 179 additions and 262 deletions

View File

@@ -1,62 +0,0 @@
import { Title } from "~/types/title";
export async function fetchTitleFromAmvstrm(
aniListId: number,
): Promise<Title | undefined> {
return Promise.all([
fetch(`https://amvstrm.up.railway.app/api/v2/info/${aniListId}`).then(
(res) => res.json<any>(),
),
fetchMissingInformationFromAnify(aniListId).catch((err) => {
console.error("Failed to get missing information from Anify", err);
return null;
}),
]).then(async ([amvstrmInfo, anifyInfo]) => {
if (amvstrmInfo.code >= 400) {
console.error(
`Error trying to load title from amvstrm; aniListId: ${aniListId}, code: ${amvstrmInfo.code}, message: ${amvstrmInfo.message}`,
);
return undefined;
}
return {
id: amvstrmInfo.id,
idMal: amvstrmInfo.idMal,
title: {
userPreferred: amvstrmInfo.title.userPreferred,
english: amvstrmInfo.title.english,
},
description: amvstrmInfo.description,
episodes: amvstrmInfo.episodes,
genres: amvstrmInfo.genres,
status: amvstrmInfo.status,
averageScore: amvstrmInfo.score.averageScore,
bannerImage: amvstrmInfo.bannerImage ?? anifyInfo?.bannerImage,
coverImage: {
extraLarge: amvstrmInfo.coverImage.extraLarge,
large: amvstrmInfo.coverImage.large,
medium: amvstrmInfo.coverImage.medium,
},
countryOfOrigin:
amvstrmInfo.countryOfOrigin ?? anifyInfo?.countryOfOrigin,
nextAiringEpisode: amvstrmInfo.nextair,
mediaListEntry: null,
};
});
}
type AnifyInformation = {
bannerImage: string | null;
countryOfOrigin: string;
};
function fetchMissingInformationFromAnify(
aniListId: number,
): Promise<AnifyInformation> {
return fetch(`https://anify.eltik.cc/info?id=${aniListId}`)
.then((res) => res.json() as Promise<AnifyInformation>)
.then(({ bannerImage, countryOfOrigin }) => ({
bannerImage,
countryOfOrigin,
}));
}

View File

@@ -22,13 +22,6 @@ describe('requests the "/title" route', () => {
expect(response.status).toBe(200);
});
it("with an unknown title from anilist but valid title from amvstrm", async () => {
const response = await app.request("/title?id=50");
expect(response.json()).resolves.toMatchSnapshot();
expect(response.status).toBe(200);
});
it("with an unknown title from all sources", async () => {
const response = await app.request("/title?id=-1");

View File

@@ -9,7 +9,6 @@ import {
} from "~/types/schema";
import { Title } from "~/types/title";
import { fetchTitleFromAmvstrm } from "./amvstrm";
import { fetchTitleFromAnilist } from "./anilist";
const app = new OpenAPIHono();
@@ -50,7 +49,6 @@ app.openapi(route, async (c) => {
const { result: title, errorOccurred } = await fetchFromMultipleSources([
() => fetchTitleFromAnilist(aniListId, aniListToken ?? undefined),
() => fetchTitleFromAmvstrm(aniListId),
]);
if (errorOccurred) {