aboutsummaryrefslogtreecommitdiff
path: root/src/lib/Data/AniList/following.ts
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-03-01 16:20:51 -0800
committerFuwn <[email protected]>2026-03-01 16:21:02 -0800
commiteae5d24d9e79e59a19d4721caaeaa0ca650ecb33 (patch)
tree1b685bb248e051dfa26d2bfdebe6689402dd93c5 /src/lib/Data/AniList/following.ts
parentchore(tooling): remove legacy eslint and prettier (diff)
downloaddue.moe-eae5d24d9e79e59a19d4721caaeaa0ca650ecb33.tar.xz
due.moe-eae5d24d9e79e59a19d4721caaeaa0ca650ecb33.zip
chore(biome): drop formatter style overrides
Diffstat (limited to 'src/lib/Data/AniList/following.ts')
-rw-r--r--src/lib/Data/AniList/following.ts88
1 files changed, 47 insertions, 41 deletions
diff --git a/src/lib/Data/AniList/following.ts b/src/lib/Data/AniList/following.ts
index bec1f53c..60bb3ccc 100644
--- a/src/lib/Data/AniList/following.ts
+++ b/src/lib/Data/AniList/following.ts
@@ -1,60 +1,66 @@
-import { user, type User } from './user';
+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: `{
+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: `{
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 userData = await user(name);
+ const activities = [];
+ let page = 1;
+ const userData = await user(name);
- if (!userData) throw new Error(`User not found: ${name}`);
+ if (!userData) throw new Error(`User not found: ${name}`);
- const id = userData.id;
- let currentPage = await followingPage(page, id);
+ const id = userData.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;
};