refactor: Replace generic AnilistDurableObject fetch endpoint with dedicated methods and update their usage.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user