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

@@ -9,32 +9,20 @@ export async function markEpisodeAsWatched(
const durableObjectId = env.ANILIST_DO.idFromName("GLOBAL");
const stub = env.ANILIST_DO.get(durableObjectId);
const operationName = markTitleAsComplete
? "MarkTitleAsWatched"
: "MarkEpisodeAsWatched";
const variables = markTitleAsComplete
? { titleId, token: aniListToken }
: { titleId, episodeNumber, token: aniListToken };
const response = await stub.fetch("http://anilist-do/graphql", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
operationName,
variables,
}),
});
if (!response.ok) {
throw new Error(
`Failed to mark episode as watched: ${response.statusText}`,
let data;
if (markTitleAsComplete) {
data = await stub.markTitleAsWatched(titleId, aniListToken);
} else {
data = await stub.markEpisodeAsWatched(
titleId,
episodeNumber,
aniListToken,
);
}
const data = (await response.json()) as any;
if (!data) {
throw new Error(`Failed to mark episode as watched`);
}
return {
...data?.user,