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

@@ -6,25 +6,19 @@ export async function getUser(aniListToken: string): Promise<User> {
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: "GetUser",
variables: { token: aniListToken },
}),
});
if (!response.ok) {
if (response.status === 401) {
let data;
try {
data = await stub.getUser(aniListToken);
} catch (e: any) {
if (e.message.includes("401")) {
return null;
}
throw new Error(`Failed to fetch user: ${response.statusText}`);
throw e;
}
const data = (await response.json()) as any;
if (!data) {
return null;
}
return {
...data,