import { aniList } from "~/consumet"; import { Episode, EpisodesResponse } from "./episode"; export async function getEpisodesFromConsumet( aniListId: number, ): Promise { 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( `Error trying to load episodes from consumet; aniListId: ${aniListId}`, ); console.error(error); } } return null; }