diff options
Diffstat (limited to 'src/lib/Data/AniList/forum.ts')
| -rw-r--r-- | src/lib/Data/AniList/forum.ts | 104 |
1 files changed, 52 insertions, 52 deletions
diff --git a/src/lib/Data/AniList/forum.ts b/src/lib/Data/AniList/forum.ts index b7b838cd..a96b74ca 100644 --- a/src/lib/Data/AniList/forum.ts +++ b/src/lib/Data/AniList/forum.ts @@ -2,75 +2,75 @@ import type { User } from './follow'; import { user } from './user'; export interface Thread { - id: number; - title: string; - createdAt: number; - mediaCategories: { - coverImage: { - extraLarge: string; - medium: string; - }; - }[]; + id: number; + title: string; + createdAt: number; + mediaCategories: { + coverImage: { + extraLarge: string; + medium: string; + }; + }[]; } export interface ThreadPage { - data: { - Page: { - threads: Thread[]; - pageInfo: { - hasNextPage: boolean; - currentPage: number; - }; - }; - }; + data: { + Page: { + threads: Thread[]; + pageInfo: { + hasNextPage: boolean; + currentPage: number; + }; + }; + }; } const threadPage = async (page: number, userId: number): Promise<ThreadPage> => - 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}) { + 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 mediaCategories { coverImage { extraLarge medium } } } pageInfo { hasNextPage } } }` - }) - }) - ).json(); + }) + }) + ).json(); export const threads = async (username: string): Promise<Thread[]> => { - const allThreads = []; - const userId = (await user(username)).id; - let page = 1; - let currentPage = await threadPage(page, userId); + 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); + for (const thread of currentPage.data.Page.threads) allThreads.push(thread); - while (currentPage.data.Page.pageInfo.hasNextPage) { - page += 1; - currentPage = await threadPage(page, userId); + while (currentPage.data.Page.pageInfo.hasNextPage) { + page += 1; + currentPage = await threadPage(page, userId); - for (const thread of currentPage.data.Page.threads) allThreads.push(thread); - } + for (const thread of currentPage.data.Page.threads) allThreads.push(thread); + } - return allThreads; + return allThreads; }; export const threadLikes = async (id: number): Promise<Partial<User>[]> => { - const activityResponse = await ( - await fetch('https://graphql.anilist.co', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - Accept: 'application/json' - }, - body: JSON.stringify({ query: `{ Thread(id: ${id}) { likes { name avatar { large } } } }` }) - }) - ).json(); + const activityResponse = await ( + await fetch('https://graphql.anilist.co', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json' + }, + body: JSON.stringify({ query: `{ Thread(id: ${id}) { likes { name avatar { large } } } }` }) + }) + ).json(); - return activityResponse['data']['Thread']['likes']; + return activityResponse['data']['Thread']['likes']; }; |