aboutsummaryrefslogtreecommitdiff
path: root/src/lib/AniList
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-12-30 21:29:33 -0800
committerFuwn <[email protected]>2023-12-30 21:29:33 -0800
commit1de5b2a41cba2e5bd3631b9a34bbd6c091918b9b (patch)
treee59c53e78dd94b9711fbf59aa5c7173159b04a16 /src/lib/AniList
parentfix(wrapped): image size for flex (diff)
downloaddue.moe-1de5b2a41cba2e5bd3631b9a34bbd6c091918b9b.tar.xz
due.moe-1de5b2a41cba2e5bd3631b9a34bbd6c091918b9b.zip
feat(tools): add follow fix base
Diffstat (limited to 'src/lib/AniList')
-rw-r--r--src/lib/AniList/follow.ts45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/lib/AniList/follow.ts b/src/lib/AniList/follow.ts
new file mode 100644
index 00000000..da477b6a
--- /dev/null
+++ b/src/lib/AniList/follow.ts
@@ -0,0 +1,45 @@
+import type { AniListAuthorisation } from './identity';
+
+export interface User {
+ id: number;
+ name: string;
+ isFollowing: boolean;
+ isFollower: boolean;
+}
+
+export const toggleFollow = async (
+ anilistAuthorisation: AniListAuthorisation,
+ username: string
+): Promise<User> => {
+ const {
+ data: { User: user }
+ } = await (
+ await fetch('https://graphql.anilist.co', {
+ method: 'POST',
+ headers: {
+ Authorization: `${anilistAuthorisation.tokenType} ${anilistAuthorisation.accessToken}`,
+ 'Content-Type': 'application/json',
+ Accept: 'application/json'
+ },
+ body: JSON.stringify({
+ query: `{ User(name: "${username}") { id } }`
+ })
+ })
+ ).json();
+
+ return (
+ await (
+ await fetch('https://graphql.anilist.co', {
+ method: 'POST',
+ headers: {
+ Authorization: `${anilistAuthorisation.tokenType} ${anilistAuthorisation.accessToken}`,
+ 'Content-Type': 'application/json',
+ Accept: 'application/json'
+ },
+ body: JSON.stringify({
+ mutation: `{ ToggleFollow(userId: ${user.id}) { id name isFollowing isFollower } }`
+ })
+ })
+ ).json()
+ )['data']['ToggleFollow'];
+};