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