aboutsummaryrefslogtreecommitdiff
path: root/src/routes/anilist/increment/+server.ts
blob: 4680236b667b8c7a2d5eca2b2ae57cacef4f9fda (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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()
	);
};