aboutsummaryrefslogtreecommitdiff
path: root/src/routes/api/preferences/pin/+server.ts
blob: 90dfce6252f27c402b86572957f94610c9455e23 (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
28
29
30
31
32
import { userIdentity } from '$lib/Data/AniList/identity';
import { toggleHololiveStreamPinning } from '$lib/Database/userPreferences';

const unauthorised = new Response('Unauthorised', { status: 401 });

export const PUT = async ({ cookies, url }) => {
	const userCookie = cookies.get('user');

	if (!userCookie) return unauthorised;

	const user = JSON.parse(userCookie);

	return Response.json(
		await toggleHololiveStreamPinning(
			(
				await userIdentity({
					tokenType: user['token_type'],
					expiresIn: user['expires_in'],
					accessToken: user['access_token'],
					refreshToken: user['refresh_token']
				})
			).id,
			url.searchParams.get('stream') || ''
		),
		{
			headers: {
				method: 'PUT',
				'Access-Control-Allow-Origin': 'https://due.moe'
			}
		}
	);
};