refactor: Replace generic AnilistDurableObject fetch endpoint with dedicated methods and update their usage.

This commit is contained in:
2025-11-29 06:22:08 -05:00
parent b1e46ad6eb
commit 25f5f80696
13 changed files with 869 additions and 655 deletions

View File

@@ -8,27 +8,13 @@ export async function fetchSearchResultsFromAnilist(
const durableObjectId = env.ANILIST_DO.idFromName("GLOBAL");
const stub = env.ANILIST_DO.get(durableObjectId);
const response = await stub.fetch("http://anilist-do/graphql", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
operationName: "Search",
variables: { query, page, limit },
}),
});
const Page = await stub.search(query, page, limit);
if (!response.ok) {
if (!Page || Page.media?.length === 0) {
return undefined;
}
const data = (await response.json()) as any;
if (!data || data.media?.length === 0) {
return undefined;
}
const { media: results, pageInfo } = data;
const { media: results, pageInfo } = Page;
return {
results: results?.map((result: any) => {
if (!result) return null;