fix: update "new episode" route to check all providers before throwing error
This commit is contained in:
@@ -3,7 +3,7 @@ import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
|
||||
import { fetchFromMultipleSources } from "~/libs/fetchFromMultipleSources";
|
||||
import { readEnvVariable } from "~/libs/readEnvVariable";
|
||||
import type { Env } from "~/types/env";
|
||||
import { EpisodesResponseSchema } from "~/types/episode";
|
||||
import { EpisodesResponse, EpisodesResponseSchema } from "~/types/episode";
|
||||
import {
|
||||
AniListIdQuerySchema,
|
||||
ErrorResponse,
|
||||
@@ -43,6 +43,23 @@ const route = createRoute({
|
||||
|
||||
const app = new OpenAPIHono<Env>();
|
||||
|
||||
export function fetchEpisodesFromAllProviders(
|
||||
aniListId: number,
|
||||
isAnifyEnabled: boolean,
|
||||
): Promise<EpisodesResponse[]> {
|
||||
return Promise.allSettled([
|
||||
import("./aniwatch").then(({ getEpisodesFromAniwatch }) =>
|
||||
getEpisodesFromAniwatch(aniListId),
|
||||
),
|
||||
getEpisodesFromAnify(isAnifyEnabled, aniListId),
|
||||
]).then((episodeResults) =>
|
||||
episodeResults
|
||||
.filter((result) => result.status === "fulfilled")
|
||||
.map((result) => result.value)
|
||||
.filter((episodes) => !!episodes),
|
||||
);
|
||||
}
|
||||
|
||||
export function fetchEpisodes(aniListId: number, isAnifyEnabled: boolean) {
|
||||
return fetchFromMultipleSources([
|
||||
() => getEpisodesFromAnify(isAnifyEnabled, aniListId),
|
||||
|
||||
Reference in New Issue
Block a user