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:
@@ -97,12 +97,12 @@ async function fetchEpisodes(
|
||||
.then(
|
||||
(res) =>
|
||||
res.json() as Promise<{
|
||||
success: boolean;
|
||||
status: number;
|
||||
data: AniwatchEpisodesResponse;
|
||||
}>,
|
||||
)
|
||||
.then(({ success, data }) => {
|
||||
if (!success || data.totalEpisodes === 0) {
|
||||
.then(({ status, data }) => {
|
||||
if (status >= 300 || data.totalEpisodes === 0) {
|
||||
console.error(
|
||||
`Error trying to load episodes from aniwatch; aniListId: ${aniListId}, totalEpisodes: ${data.totalEpisodes}`,
|
||||
);
|
||||
@@ -164,12 +164,12 @@ function getAniwatchId(
|
||||
}
|
||||
|
||||
const json = (await res.value.json()) as {
|
||||
success: boolean;
|
||||
status: number;
|
||||
data: AniwatchSearchResponse;
|
||||
};
|
||||
const currentValue = await current;
|
||||
return {
|
||||
success: currentValue.success || json.success,
|
||||
success: currentValue.success || json.status === 200,
|
||||
data: {
|
||||
...currentValue.data,
|
||||
animes: [
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
import { aniList } from "~/consumet";
|
||||
|
||||
import { Episode, EpisodesResponse } from "./episode";
|
||||
|
||||
export async function getEpisodesFromConsumet(
|
||||
aniListId: number,
|
||||
): Promise<EpisodesResponse | null> {
|
||||
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;
|
||||
}
|
||||
@@ -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 },
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user