blob: 2d51c87aff39e9dd8fd7544c06be413a7bcf05ee (
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
import { userIdentity } from '$lib/Data/AniList/identity';
import { getUserPreferences, toggleHideMissingBadges, setCSS } from '$lib/Database/userPreferences';
const unauthorised = new Response('Unauthorised', { status: 401 });
export const GET = async ({ url }) => {
const preferences = await getUserPreferences(Number(url.searchParams.get('id') || 0));
return Response.json(preferences ? preferences : {}, {
headers: {
'Access-Control-Allow-Origin': 'https://due.moe'
}
});
};
export const PUT = async ({ url, cookies, request }) => {
const userCookie = cookies.get('user');
if (!userCookie) return unauthorised;
const user = JSON.parse(userCookie);
const userId = (
await userIdentity({
tokenType: user['token_type'],
expiresIn: user['expires_in'],
accessToken: user['access_token'],
refreshToken: user['refresh_token']
})
).id;
if (url.searchParams.get('toggleHideMissingBadges') !== null) {
return Response.json(await toggleHideMissingBadges(userId), {
headers: {
'Access-Control-Allow-Origin': 'https://due.moe'
}
});
}
if (url.searchParams.get('badgeWallCSS') !== null) {
return Response.json(await setCSS(userId, await request.text()), {
headers: {
'Access-Control-Allow-Origin': 'https://due.moe'
}
});
}
return Response.json(await getUserPreferences(Number(url.searchParams.get('id') || 0)), {
headers: {
'Access-Control-Allow-Origin': 'https://due.moe'
}
});
};
|