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:
@@ -4,11 +4,10 @@ import { streamSSE } from "hono/streaming";
|
||||
|
||||
import { fetchEpisodes } from "~/controllers/episodes/getByAniListId";
|
||||
import { maybeScheduleNextAiringEpisode } from "~/libs/maybeScheduleNextAiringEpisode";
|
||||
import { sleep } from "~/libs/sleep";
|
||||
import { associateDeviceIdWithUsername } from "~/models/token";
|
||||
import { setWatchStatus } from "~/models/watchStatus";
|
||||
import type { Env } from "~/types/env";
|
||||
import { Episode, EpisodesResponseSchema } from "~/types/episode";
|
||||
import { EpisodesResponseSchema } from "~/types/episode";
|
||||
import { ErrorResponse, ErrorResponseSchema } from "~/types/schema";
|
||||
import { Title } from "~/types/title";
|
||||
|
||||
@@ -186,13 +185,8 @@ app.openapi(route, async (c) => {
|
||||
continue;
|
||||
}
|
||||
|
||||
await fetchEpisodes(
|
||||
media.id,
|
||||
{ ...env(c, "workerd"), ENABLE_ANIFY: "false" },
|
||||
true,
|
||||
).then(({ result: episodesResult }) => {
|
||||
const episodes = episodesResult?.episodes;
|
||||
if (!episodes) {
|
||||
await fetchEpisodes(media.id, true).then(({ episodes }) => {
|
||||
if (episodes.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 },
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -36,12 +36,12 @@ async function getEpisodeUrl(watchId: string, server?: string) {
|
||||
.then(
|
||||
(res) =>
|
||||
res.json() as Promise<{
|
||||
success: boolean;
|
||||
status: number;
|
||||
data: AniwatchEpisodeUrlResponse;
|
||||
}>,
|
||||
)
|
||||
.then(({ success, data }) => {
|
||||
if (!success || !data.sources || data.sources.length === 0) {
|
||||
.then(({ status, data }) => {
|
||||
if (status >= 300 || !data.sources || data.sources.length === 0) {
|
||||
return { source: null };
|
||||
}
|
||||
|
||||
@@ -50,9 +50,10 @@ async function getEpisodeUrl(watchId: string, server?: string) {
|
||||
intro: convertSkipTime(intro),
|
||||
outro: convertSkipTime(outro),
|
||||
source: sources[0].url,
|
||||
subtitles: tracks
|
||||
.filter(({ kind }) => kind === "captions")
|
||||
.map(({ file, label }) => ({ url: file, lang: label ?? "" })),
|
||||
subtitles: tracks.map(({ url, lang }) => ({
|
||||
url,
|
||||
lang,
|
||||
})),
|
||||
headers,
|
||||
};
|
||||
});
|
||||
@@ -79,8 +80,8 @@ async function getEpisodeServers(watchId: string) {
|
||||
)
|
||||
.then((res) => res.json() as Promise<AniwatchEpisodeServersResponse>)
|
||||
.then((res) => {
|
||||
if (!res.success) {
|
||||
throw new Error(res.message);
|
||||
if (res.status >= 300 || !res.data) {
|
||||
throw new Error("Failed to fetch episode servers");
|
||||
}
|
||||
|
||||
return res;
|
||||
@@ -105,21 +106,16 @@ interface Source {
|
||||
}
|
||||
|
||||
interface Track {
|
||||
file: string;
|
||||
label?: string;
|
||||
url: string;
|
||||
lang?: string;
|
||||
kind: string;
|
||||
default?: boolean;
|
||||
}
|
||||
|
||||
type AniwatchEpisodeServersResponse =
|
||||
| {
|
||||
success: true;
|
||||
data: AniwatchEpisodeServers;
|
||||
}
|
||||
| {
|
||||
success: false;
|
||||
message: string;
|
||||
};
|
||||
interface AniwatchEpisodeServersResponse {
|
||||
status: number;
|
||||
data: AniwatchEpisodeServers;
|
||||
}
|
||||
|
||||
interface AniwatchEpisodeServers {
|
||||
sub: AniwatchEpisodeServer[];
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
import { aniList } from "~/consumet";
|
||||
import { sortByProperty } from "~/libs/sortByProperty";
|
||||
import type { FetchUrlResponse } from "~/types/episode/fetch-url-response";
|
||||
|
||||
import { qualityPriority, subtitlesPriority } from "./priorities";
|
||||
|
||||
export async function getSourcesFromConsumet(
|
||||
watchId: string,
|
||||
): Promise<FetchUrlResponse | null> {
|
||||
try {
|
||||
const { sources, subtitles, intro, outro } =
|
||||
await aniList.fetchEpisodeSources(watchId);
|
||||
|
||||
if (sources.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const source = sources.sort(sortByProperty(qualityPriority, "quality"))[0]
|
||||
?.url;
|
||||
subtitles?.sort(sortByProperty(subtitlesPriority, "lang"));
|
||||
|
||||
return {
|
||||
source,
|
||||
subtitles: subtitles ?? [],
|
||||
audio: [],
|
||||
intro: intro ? [intro.start, intro.end] : undefined,
|
||||
outro: outro ? [outro.start, outro.end] : undefined,
|
||||
};
|
||||
} catch (error) {
|
||||
if (error.message === "Episode not found.") {
|
||||
return null;
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -6,14 +6,13 @@ import { server } from "~/mocks";
|
||||
server.listen();
|
||||
|
||||
describe('requests the "/episodes/:id/url" route', () => {
|
||||
it("with sources from Anify", async () => {
|
||||
it("with sources from Aniwatch", async () => {
|
||||
const response = await app.request(
|
||||
"/episodes/1/url",
|
||||
"/episodes/4/url",
|
||||
{
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
provider: "anify",
|
||||
id: "/ore-dake-level-up-na-ken-episode-2",
|
||||
episodeNumber: 1,
|
||||
}),
|
||||
headers: { "Content-Type": "application/json" },
|
||||
},
|
||||
@@ -26,19 +25,18 @@ describe('requests the "/episodes/:id/url" route', () => {
|
||||
success: true,
|
||||
result: {
|
||||
source:
|
||||
"https://proxy.anify.tv/video/8CLGIJg8G3k%252BH%252BYV9xyOYVGZ8al8uZqqtbXk44wKRco%252BGATkCrqlkgdRiam3owmOU4f2MAB89GOblOuZbxifwbGsjvp32uxhRC4kZVYrWnZmP%252FrLxtqwi0n6zY%252BvrffUh6dbg6DADSLCWhd2bNUUIg%253D%253D/%7B%7D/.m3u8",
|
||||
"https://www032.vipanicdn.net/streamhls/aa804a2400535d84dd59454b28d329fb/ep.1.1712504065.m3u8",
|
||||
subtitles: [],
|
||||
audio: [],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("with no URL from Anify source", async () => {
|
||||
it("with no URL from Aniwatch source", async () => {
|
||||
const response = await app.request("/episodes/-1/url", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
provider: "anify",
|
||||
id: "/ore-dake-level-up-na-ken-episode-2",
|
||||
episodeNumber: -1,
|
||||
}),
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
@@ -46,85 +44,4 @@ describe('requests the "/episodes/:id/url" route', () => {
|
||||
expect(response.json()).resolves.toEqual({ success: false });
|
||||
expect(response.status).toBe(404);
|
||||
});
|
||||
|
||||
it("with sources from Consumet", async () => {
|
||||
const response = await app.request(
|
||||
"/episodes/1/url",
|
||||
{
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
provider: "consumet",
|
||||
id: "/ore-dake-level-up-na-ken-episode-2",
|
||||
}),
|
||||
headers: { "Content-Type": "application/json" },
|
||||
},
|
||||
{
|
||||
ENABLE_ANIFY: "true",
|
||||
},
|
||||
);
|
||||
|
||||
expect(response.json()).resolves.toEqual({
|
||||
success: true,
|
||||
result: {
|
||||
source: "https://consumet.com",
|
||||
subtitles: [],
|
||||
audio: [],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("with no URL from Consumet source", async () => {
|
||||
const response = await app.request("/episodes/-1/url", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
provider: "consumet",
|
||||
id: "unknown",
|
||||
}),
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
|
||||
expect(response.json()).resolves.toEqual({ success: false });
|
||||
expect(response.status).toBe(404);
|
||||
});
|
||||
|
||||
// it("with sources from Aniwatch", async () => {
|
||||
// const response = await app.request(
|
||||
// "/episodes/1/url",
|
||||
// {
|
||||
// method: "POST",
|
||||
// body: JSON.stringify({
|
||||
// provider: "aniwatch",
|
||||
// id: "ore-dake-level-up-na-ken-episode-2",
|
||||
// }),
|
||||
// headers: { "Content-Type": "application/json" },
|
||||
// },
|
||||
// {
|
||||
// ENABLE_ANIFY: "true",
|
||||
// },
|
||||
// );
|
||||
|
||||
// expect(response.json()).resolves.toEqual({
|
||||
// success: true,
|
||||
// result: {
|
||||
// source:
|
||||
// "https://www032.vipanicdn.net/streamhls/aa804a2400535d84dd59454b28d329fb/ep.1.1712504065.m3u8",
|
||||
// subtitles: [],
|
||||
// audio: [],
|
||||
// },
|
||||
// });
|
||||
// });
|
||||
|
||||
// it("with no URL from Aniwatch source", async () => {
|
||||
// const response = await app.request("/episodes/-1/url", {
|
||||
// method: "POST",
|
||||
// body: JSON.stringify({
|
||||
// provider: "aniwatch",
|
||||
// id: "unknown",
|
||||
// }),
|
||||
// headers: { "Content-Type": "application/json" },
|
||||
// });
|
||||
|
||||
// expect(response.json()).resolves.toEqual({ success: false });
|
||||
// expect(response.status).toBe(404);
|
||||
// });
|
||||
});
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
|
||||
import { env } from "hono/adapter";
|
||||
|
||||
import { readEnvVariable } from "~/libs/readEnvVariable";
|
||||
import type { Env } from "~/types/env";
|
||||
import type { Episode } from "~/types/episode";
|
||||
import { FetchUrlResponse } from "~/types/episode/fetch-url-response";
|
||||
import {
|
||||
AniListIdQuerySchema,
|
||||
@@ -12,12 +9,9 @@ import {
|
||||
ErrorResponseSchema,
|
||||
} from "~/types/schema";
|
||||
|
||||
import { fetchEpisodesFromAllProviders } from "../getByAniListId";
|
||||
import { fetchEpisodes } from "../getByAniListId";
|
||||
|
||||
const FetchUrlRequest = z.union([
|
||||
z.object({ id: z.string(), provider: z.string() }),
|
||||
z.object({ episodeNumber: EpisodeNumberSchema }),
|
||||
]);
|
||||
const FetchUrlRequest = z.object({ episodeNumber: EpisodeNumberSchema });
|
||||
|
||||
const route = createRoute({
|
||||
tags: ["aniplay", "episodes"],
|
||||
@@ -73,89 +67,40 @@ const route = createRoute({
|
||||
|
||||
const app = new OpenAPIHono<Env>();
|
||||
|
||||
export async function fetchEpisodeUrlFromAllProviders(
|
||||
aniListId: number,
|
||||
episodeNumber: number,
|
||||
env: Env,
|
||||
) {
|
||||
const results = await fetchEpisodesFromAllProviders(aniListId, env);
|
||||
if (results.length === 0) {
|
||||
return { episodes: null, fetchUrlResult: null };
|
||||
}
|
||||
|
||||
let episodes: Episode[] | null = null;
|
||||
let fetchUrlResult: FetchUrlResponse | null = null;
|
||||
|
||||
for (const { episodes: episodesResult, providerId } of results) {
|
||||
const episode = episodesResult.find(
|
||||
(episode) => episode.number === episodeNumber,
|
||||
);
|
||||
if (!episode) {
|
||||
continue;
|
||||
}
|
||||
episodes = episodesResult;
|
||||
|
||||
const urlResult = await fetchEpisodeUrl(
|
||||
providerId,
|
||||
episode.id,
|
||||
aniListId,
|
||||
readEnvVariable(env, "ENABLE_ANIFY"),
|
||||
);
|
||||
if (!urlResult) {
|
||||
episodes = null;
|
||||
continue;
|
||||
}
|
||||
|
||||
fetchUrlResult = urlResult;
|
||||
break;
|
||||
}
|
||||
|
||||
return { episodes, fetchUrlResult };
|
||||
}
|
||||
|
||||
export async function fetchEpisodeUrl(
|
||||
provider: string,
|
||||
id: string,
|
||||
aniListId: number,
|
||||
isAnifyEnabled: boolean,
|
||||
): Promise<FetchUrlResponse | null> {
|
||||
if (provider === "consumet" || !isAnifyEnabled) {
|
||||
try {
|
||||
const result = await import("./consumet").then(
|
||||
({ getSourcesFromConsumet }) => getSourcesFromConsumet(id),
|
||||
);
|
||||
if (!result) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (e) {
|
||||
console.error("Failed to fetch download URL from Consumet", e);
|
||||
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
if (provider === "aniwatch") {
|
||||
try {
|
||||
const result = await import("./aniwatch").then(
|
||||
({ getSourcesFromAniwatch }) => getSourcesFromAniwatch(id),
|
||||
);
|
||||
if (!result) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (e) {
|
||||
console.error("Failed to fetch download URL from Aniwatch", e);
|
||||
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchEpisodeUrl({
|
||||
id,
|
||||
aniListId,
|
||||
episodeNumber,
|
||||
}:
|
||||
| { id: string; aniListId?: number; episodeNumber?: number }
|
||||
| {
|
||||
id?: string;
|
||||
aniListId: number;
|
||||
episodeNumber: number;
|
||||
}): Promise<FetchUrlResponse | null> {
|
||||
try {
|
||||
const result = await import("./anify").then(({ getSourcesFromAnify }) =>
|
||||
getSourcesFromAnify(provider, id, aniListId),
|
||||
let episodeId = id;
|
||||
if (!id) {
|
||||
const episodes = await fetchEpisodes(aniListId!);
|
||||
if (episodes.length === 0) {
|
||||
console.error(`Failed to fetch episodes for title ${aniListId}`);
|
||||
return null;
|
||||
}
|
||||
const episode = episodes.find(
|
||||
(episode) => episode.number === episodeNumber,
|
||||
);
|
||||
if (!episode) {
|
||||
console.error(
|
||||
`Episode ${episodeNumber} not found for title ${aniListId}`,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
episodeId = episode.id;
|
||||
}
|
||||
|
||||
const result = await import("./aniwatch").then(
|
||||
({ getSourcesFromAniwatch }) => getSourcesFromAniwatch(episodeId!),
|
||||
);
|
||||
if (!result) {
|
||||
return null;
|
||||
@@ -163,7 +108,7 @@ export async function fetchEpisodeUrl(
|
||||
|
||||
return result;
|
||||
} catch (e) {
|
||||
console.error("Failed to fetch download URL from Anify", e);
|
||||
console.error("Failed to fetch download URL from Aniwatch", e);
|
||||
|
||||
throw e;
|
||||
}
|
||||
@@ -171,37 +116,21 @@ export async function fetchEpisodeUrl(
|
||||
|
||||
app.openapi(route, async (c) => {
|
||||
const aniListId = Number(c.req.param("aniListId"));
|
||||
const { provider, id, episodeNumber } =
|
||||
await c.req.json<typeof FetchUrlRequest._type>();
|
||||
if (!provider && episodeNumber == undefined) {
|
||||
const { episodeNumber } = await c.req.json<typeof FetchUrlRequest._type>();
|
||||
if (episodeNumber == undefined) {
|
||||
return c.json(ErrorResponse, { status: 400 });
|
||||
}
|
||||
|
||||
try {
|
||||
const isAnifyEnabled = readEnvVariable<boolean>(c.env, "ENABLE_ANIFY");
|
||||
let result: FetchUrlResponse | null;
|
||||
if (provider) {
|
||||
console.log(`Fetching sources from ${provider} for ${aniListId}`);
|
||||
result = await fetchEpisodeUrl(provider, id, aniListId, isAnifyEnabled);
|
||||
} else {
|
||||
console.log(`Fetching sources from all providers for ${aniListId}`);
|
||||
const { fetchUrlResult } = await fetchEpisodeUrlFromAllProviders(
|
||||
aniListId,
|
||||
episodeNumber!,
|
||||
env(c, "workerd"),
|
||||
);
|
||||
if (!fetchUrlResult) {
|
||||
return c.json(ErrorResponse, { status: 404 });
|
||||
}
|
||||
|
||||
result = fetchUrlResult;
|
||||
}
|
||||
|
||||
if (result) {
|
||||
return c.json({ success: true, result });
|
||||
} else {
|
||||
console.log(
|
||||
`Fetching episode URL for aniListId: ${aniListId}, episodeNumber: ${episodeNumber}`,
|
||||
);
|
||||
const fetchUrlResult = await fetchEpisodeUrl({ aniListId, episodeNumber });
|
||||
if (!fetchUrlResult) {
|
||||
return c.json(ErrorResponse, { status: 404 });
|
||||
}
|
||||
|
||||
return c.json({ success: true, result: fetchUrlResult });
|
||||
} catch (error) {
|
||||
return c.json(ErrorResponse, { status: 500 });
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { Hono } from "hono";
|
||||
import { env } from "hono/adapter";
|
||||
import { z } from "zod";
|
||||
|
||||
import { fetchEpisodeUrlFromAllProviders } from "~/controllers/episodes/getEpisodeUrl";
|
||||
import { fetchEpisodeUrl } from "~/controllers/episodes/getEpisodeUrl";
|
||||
import { getAdminSdkCredentials } from "~/libs/gcloud/getAdminSdkCredentials";
|
||||
import { sendFcmMessage } from "~/libs/gcloud/sendFcmMessage";
|
||||
import { maybeScheduleNextAiringEpisode } from "~/libs/maybeScheduleNextAiringEpisode";
|
||||
@@ -44,20 +44,7 @@ app.post(
|
||||
);
|
||||
}
|
||||
|
||||
const { episodes, fetchUrlResult } = await fetchEpisodeUrlFromAllProviders(
|
||||
aniListId,
|
||||
episodeNumber,
|
||||
env<Env, typeof c>(c, "workerd"),
|
||||
);
|
||||
|
||||
if (!episodes) {
|
||||
console.error(`Failed to fetch episodes for title ${aniListId}`);
|
||||
return c.json(
|
||||
{ success: false, message: "Failed to fetch episodes" },
|
||||
500,
|
||||
);
|
||||
}
|
||||
|
||||
const fetchUrlResult = await fetchEpisodeUrl({ aniListId, episodeNumber });
|
||||
if (!fetchUrlResult) {
|
||||
console.error(`Failed to fetch episode URL for episode`);
|
||||
return c.json(
|
||||
|
||||
@@ -66,3 +66,10 @@ app.doc("/openapi.json", {
|
||||
app.get("/docs", swaggerUI({ url: "/openapi.json" }));
|
||||
|
||||
export default app;
|
||||
|
||||
export class AniwatchApiContainer /* extends Container */ {
|
||||
// Port the container listens on (default: 8080)
|
||||
defaultPort = 4444;
|
||||
// Time before container sleeps due to inactivity (default: 30s)
|
||||
sleepAfter = "2m";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user