aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-09-22 23:39:34 -0700
committerFuwn <[email protected]>2023-09-22 23:39:34 -0700
commit1682e048fae37c482d20922b3c261dc83bcc0ba7 (patch)
treef5ec98c3870e0c45368d9d89871f50f627aac48c /src/lib
parentfix(settings): feedback line breaks (diff)
downloaddue.moe-1682e048fae37c482d20922b3c261dc83bcc0ba7.tar.xz
due.moe-1682e048fae37c482d20922b3c261dc83bcc0ba7.zip
feat(routes): tools
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/AniList/character.ts66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/lib/AniList/character.ts b/src/lib/AniList/character.ts
new file mode 100644
index 00000000..27caef99
--- /dev/null
+++ b/src/lib/AniList/character.ts
@@ -0,0 +1,66 @@
+export interface Character {
+ name: {
+ full: string;
+ };
+ id: number;
+}
+
+export interface CharactersPage {
+ data: {
+ Page: {
+ characters: Character[];
+ pageInfo: {
+ hasNextPage: boolean;
+ currentPage: number;
+ };
+ };
+ };
+}
+
+const charactersPage = async (page: number): Promise<CharactersPage> =>
+ await (
+ await fetch('https://graphql.anilist.co', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ Accept: 'application/json'
+ },
+ body: JSON.stringify({
+ query: `{ Page(page: ${page}, perPage: 50) {
+ characters(isBirthday: true) { name { full } id }
+ pageInfo { hasNextPage currentPage }
+ } }`
+ })
+ })
+ ).json();
+
+export const todaysCharacterBirthdays = async (): Promise<Character[]> => {
+ const characters = [];
+ let page = 1;
+ let currentPage = await charactersPage(page);
+
+ for (const character of currentPage['data']['Page']['characters']) {
+ characters.push({
+ id: character['id'],
+ name: {
+ full: character['name']['full']
+ }
+ });
+ }
+
+ while (currentPage['data']['Page']['pageInfo']['hasNextPage']) {
+ for (const character of currentPage['data']['Page']['characters']) {
+ characters.push({
+ id: character['id'],
+ name: {
+ full: character['name']['full']
+ }
+ });
+ }
+
+ page += 1;
+ currentPage = await charactersPage(page);
+ }
+
+ return characters;
+};