refactor: move fetchEpisodes in to subfolder

This commit is contained in:
2024-05-29 08:37:51 -04:00
parent d19f76689c
commit 8b6aecca5c
7 changed files with 1 additions and 1 deletions

View File

@@ -0,0 +1,45 @@
import { ANIME, META } from "@consumet/extensions";
import fetchAdapter from "@haverstack/axios-fetch-adapter";
import { Episode, EpisodesResponse } from "./episode";
export async function getEpisodesFromConsumet(
aniListId: number,
): Promise<EpisodesResponse | null> {
const gogoAnime = new ANIME.Gogoanime(undefined, undefined, fetchAdapter);
const aniList = new META.Anilist(gogoAnime, undefined, fetchAdapter);
try {
const episodes: Episode[] = await aniList
.fetchEpisodesListById(aniListId.toString())
.then((episodes) =>
episodes.map(
({ id, number, title, image: img, description }): Episode => ({
id,
number,
title,
img,
description,
rating: undefined,
updatedAt: 0,
}),
),
);
if (!episodes || episodes.length === 0) {
return null;
}
return { providerId: "consumet", episodes };
} catch (error: any) {
if (!error.message.includes("failed with status code")) {
console.error(
new Error(
`Error trying to load episodes from consumet; aniListId: ${aniListId}`,
{ cause: error },
),
);
}
}
return null;
}