From 0c6fbd9b1afe8e5967a127bffa68570ee88bfe92 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sun, 22 Oct 2023 14:03:08 -0700 Subject: feat(tools): episode discussion collector --- src/lib/AniList/forum.ts | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/lib/AniList/forum.ts (limited to 'src/lib/AniList') diff --git a/src/lib/AniList/forum.ts b/src/lib/AniList/forum.ts new file mode 100644 index 00000000..6b95fa07 --- /dev/null +++ b/src/lib/AniList/forum.ts @@ -0,0 +1,58 @@ +import { user } from './user'; + +export interface Thread { + id: number; + title: string; + createdAt: number; +} + +export interface ThreadPage { + data: { + Page: { + threads: Thread[]; + pageInfo: { + hasNextPage: boolean; + currentPage: number; + }; + }; + }; +} + +const threadPage = async (page: number, userId: number): Promise => + await ( + await fetch('https://graphql.anilist.co', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json' + }, + body: JSON.stringify({ + query: `{ Page(perPage: 50, page: ${page}) { + threads(userId: ${userId}) { id title createdAt } + pageInfo { hasNextPage } +} }` + }) + }) + ).json(); + +export const threads = async (username: string): Promise => { + const allThreads = []; + const userId = (await user(username)).id; + let page = 1; + let currentPage = await threadPage(page, userId); + + for (const thread of currentPage.data.Page.threads) { + allThreads.push(thread); + } + + while (currentPage.data.Page.pageInfo.hasNextPage) { + page += 1; + currentPage = await threadPage(page, userId); + + for (const thread of currentPage.data.Page.threads) { + allThreads.push(thread); + } + } + + return allThreads; +}; -- cgit v1.2.3 From f99fd41ee23d7669812ff1d88d23a9b7f22db901 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Tue, 24 Oct 2023 18:18:37 -0700 Subject: feat(user): prettier user route --- src/lib/AniList/user.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/lib/AniList') diff --git a/src/lib/AniList/user.ts b/src/lib/AniList/user.ts index dd9995fd..fdc98a58 100644 --- a/src/lib/AniList/user.ts +++ b/src/lib/AniList/user.ts @@ -15,6 +15,9 @@ export interface User { volumesRead: number; }; }; + avatar: { + large: string; + }; } export const user = async (username: string): Promise => { @@ -28,7 +31,7 @@ export const user = async (username: string): Promise => { }, body: JSON.stringify({ query: `{ User(name: "${username}") { - name id statistics { + name id avatar { large } statistics { anime { count meanScore minutesWatched episodesWatched } -- cgit v1.2.3