diff options
| author | Fuwn <[email protected]> | 2024-10-09 00:41:20 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-10-09 00:41:43 -0700 |
| commit | 998b63a35256ac985a5a2714dd1ca451af4dfd8a (patch) | |
| tree | 50796121a9d5ab0330fdc5d7e098bda2860d9726 /src/lib/Data/AniList/following.ts | |
| parent | feat(graphql): add badgeCount field (diff) | |
| download | due.moe-998b63a35256ac985a5a2714dd1ca451af4dfd8a.tar.xz due.moe-998b63a35256ac985a5a2714dd1ca451af4dfd8a.zip | |
chore(prettier): use spaces instead of tabs
Diffstat (limited to 'src/lib/Data/AniList/following.ts')
| -rw-r--r-- | src/lib/Data/AniList/following.ts | 72 |
1 files changed, 36 insertions, 36 deletions
diff --git a/src/lib/Data/AniList/following.ts b/src/lib/Data/AniList/following.ts index 1bba66b9..b4772afa 100644 --- a/src/lib/Data/AniList/following.ts +++ b/src/lib/Data/AniList/following.ts @@ -1,56 +1,56 @@ import { user, type User } from './user'; export interface FollowingPage { - data: { - Page: { - pageInfo: { - hasNextPage: boolean; - }; - following: Partial<User>[]; - }; - }; + data: { + Page: { + pageInfo: { + hasNextPage: boolean; + }; + following: Partial<User>[]; + }; + }; } const followingPage = async (page: number, id: number): Promise<FollowingPage> => - await ( - await fetch('https://graphql.anilist.co', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - Accept: 'application/json' - }, - body: JSON.stringify({ - query: `{ + await ( + await fetch('https://graphql.anilist.co', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json' + }, + body: JSON.stringify({ + query: `{ Page(page: ${page}) { pageInfo { hasNextPage } following(userId: ${id}) { name id } } }` - }) - }) - ).json(); + }) + }) + ).json(); export const followers = async (name: string): Promise<Partial<User>[]> => { - const activities = []; - let page = 1; - const id = (await user(name)).id; - let currentPage = await followingPage(page, id); + const activities = []; + let page = 1; + const id = (await user(name)).id; + let currentPage = await followingPage(page, id); - for (const activity of currentPage.data.Page.following) activities.push(activity); + for (const activity of currentPage.data.Page.following) activities.push(activity); - while (currentPage['data']['Page']['pageInfo']['hasNextPage']) { - for (const activity of currentPage.data.Page.following) activities.push(activity); + while (currentPage['data']['Page']['pageInfo']['hasNextPage']) { + for (const activity of currentPage.data.Page.following) activities.push(activity); - page += 1; - currentPage = await followingPage(page, id); - } + page += 1; + currentPage = await followingPage(page, id); + } - for (const activity of currentPage.data.Page.following) activities.push(activity); + for (const activity of currentPage.data.Page.following) activities.push(activity); - for (let i = activities.length - 1; i > 0; i--) { - const j = Math.floor(Math.random() * (i + 1)); - [activities[i], activities[j]] = [activities[j], activities[i]]; - } + for (let i = activities.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [activities[i], activities[j]] = [activities[j], activities[i]]; + } - return activities; + return activities; }; |