aboutsummaryrefslogtreecommitdiff
path: root/src/routes/api
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-09-13 01:46:20 -0700
committerFuwn <[email protected]>2023-09-13 01:46:20 -0700
commitd6fe2c594a170553e9b88efc6338456dfd13391c (patch)
tree86732b0cb44ea02a8a329780b120c63e4c561d58 /src/routes/api
parentfix(updates): fetch before parse (diff)
downloaddue.moe-d6fe2c594a170553e9b88efc6338456dfd13391c.tar.xz
due.moe-d6fe2c594a170553e9b88efc6338456dfd13391c.zip
refactor(anilist): move to api
Diffstat (limited to 'src/routes/api')
-rw-r--r--src/routes/api/anilist/increment/+server.ts27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/routes/api/anilist/increment/+server.ts b/src/routes/api/anilist/increment/+server.ts
new file mode 100644
index 00000000..4680236b
--- /dev/null
+++ b/src/routes/api/anilist/increment/+server.ts
@@ -0,0 +1,27 @@
+export const GET = async ({ url, cookies }) => {
+ const userCookie = cookies.get('user');
+
+ if (!userCookie) {
+ return new Response('Unauthenticated', { status: 401 });
+ }
+
+ const user = JSON.parse(userCookie);
+
+ return Response.json(
+ await (
+ await fetch('https://graphql.anilist.co', {
+ method: 'POST',
+ headers: {
+ Authorization: `${user['token_type']} ${user['access_token']}`,
+ 'Content-Type': 'application/json',
+ Accept: 'application/json'
+ },
+ body: JSON.stringify({
+ query: `mutation { SaveMediaListEntry(mediaId: ${
+ url.searchParams.get('id') || 'null'
+ }, progress: ${url.searchParams.get('progress') || 'null'}) { id } }`
+ })
+ })
+ ).json()
+ );
+};