Some checks failed
Deploy / Deploy (push) Has been cancelled
also removed any references to Anify
46 lines
1.1 KiB
TypeScript
46 lines
1.1 KiB
TypeScript
import { env } from "cloudflare:workers";
|
|
import { graphql } from "gql.tada";
|
|
import { GraphQLError } from "graphql";
|
|
|
|
import type { GraphQLContext } from "~/graph~/context";
|
|
import { MediaFragment } from "~/types/title/mediaFragment";
|
|
|
|
enum HomeCategory {
|
|
WATCHING,
|
|
PLANNING,
|
|
}
|
|
|
|
export async function home(
|
|
_parent: any,
|
|
args: { category: HomeCategory; page?: number },
|
|
context: GraphQLContext,
|
|
) {
|
|
const { category, page = 1 } = args;
|
|
const { user, aniListToken } = context;
|
|
let statusFilters: string[] = [];
|
|
switch (category) {
|
|
case HomeCategory.WATCHING:
|
|
statusFilters = ["CURRENT"];
|
|
break;
|
|
case HomeCategory.PLANNING:
|
|
statusFilters = ["PLANNING", "PAUSED", "REPEATING"];
|
|
break;
|
|
}
|
|
|
|
const stub = await env.ANILIST_DO.getByName("GLOBAL");
|
|
const response = await stub.getTitles(
|
|
user?.name,
|
|
page,
|
|
statusFilters,
|
|
aniListToken,
|
|
);
|
|
|
|
if (!response) {
|
|
throw new GraphQLError(`Failed to fetch ${category} titles`, {
|
|
extensions: { code: "INTERNAL_SERVER_ERROR" },
|
|
});
|
|
}
|
|
|
|
return response;
|
|
}
|