fix(aniplay): Migrates to Aniwatch only

Removes Consumet and consolidates episode fetching to use Aniwatch as the sole provider.

This simplifies the codebase and ensures a consistent data source for episodes and URLs.
Also updates `wrangler` and sets `ENABLE_ANIFY` to false.
This commit is contained in:
2025-08-08 08:16:39 -07:00
parent d680c97bc6
commit 0b0078328c
13 changed files with 95 additions and 380 deletions

View File

@@ -1,17 +1,13 @@
import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
import { env } from "hono/adapter";
import { fetchFromMultipleSources } from "~/libs/fetchFromMultipleSources";
import type { Env } from "~/types/env";
import { EpisodesResponse, EpisodesResponseSchema } from "~/types/episode";
import { EpisodesResponseSchema } from "~/types/episode";
import {
AniListIdQuerySchema,
ErrorResponse,
ErrorResponseSchema,
} from "~/types/schema";
import { getEpisodesFromAnify } from "./anify";
const route = createRoute({
tags: ["aniplay", "episodes"],
summary: "Fetch episodes for a title",
@@ -43,61 +39,25 @@ const route = createRoute({
const app = new OpenAPIHono<Env>();
export function fetchEpisodesFromAllProviders(
aniListId: number,
env: Env,
): Promise<EpisodesResponse[]> {
return Promise.allSettled([
import("./aniwatch").then(({ getEpisodesFromAniwatch }) =>
getEpisodesFromAniwatch(aniListId),
),
getEpisodesFromAnify(env, aniListId),
]).then((episodeResults) =>
episodeResults
.filter((result) => result.status === "fulfilled")
.map((result) => result.value)
.filter((episodes) => !!episodes),
);
}
export function fetchEpisodes(
aniListId: number,
env: Env,
shouldRetry: boolean = false,
) {
return fetchFromMultipleSources([
() =>
import("./aniwatch").then(({ getEpisodesFromAniwatch }) =>
getEpisodesFromAniwatch(aniListId, shouldRetry),
),
() => getEpisodesFromAnify(env, aniListId),
// () =>
// import("./consumet").then(({ getEpisodesFromConsumet }) =>
// getEpisodesFromConsumet(aniListId),
// ),
]);
export function fetchEpisodes(aniListId: number, shouldRetry: boolean = false) {
return import("./aniwatch")
.then(({ getEpisodesFromAniwatch }) =>
getEpisodesFromAniwatch(aniListId, shouldRetry),
)
.then((episodeResults) => episodeResults?.episodes ?? []);
}
app.openapi(route, async (c) => {
const aniListId = Number(c.req.param("aniListId"));
const { result, errorOccurred } = await fetchEpisodes(
aniListId,
env(c, "workerd"),
);
if (errorOccurred || !result) {
return c.json(ErrorResponse, { status: 500 });
}
const { episodes, providerId } = result;
if (!episodes || episodes.length === 0) {
const episodes = await fetchEpisodes(aniListId);
if (episodes.length === 0) {
return c.json(ErrorResponse, { status: 404 });
}
return c.json({
success: true,
result: { providerId, episodes },
result: { providerId: "aniwatch", episodes },
});
});