diff options
Diffstat (limited to 'src/routes/api')
| -rw-r--r-- | src/routes/api/preferences/+server.ts | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/src/routes/api/preferences/+server.ts b/src/routes/api/preferences/+server.ts index c69b4096..2d51c87a 100644 --- a/src/routes/api/preferences/+server.ts +++ b/src/routes/api/preferences/+server.ts @@ -1,4 +1,7 @@ -import { getUserPreferences, toggleHideMissingBadges } from '$lib/Database/userPreferences'; +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)); @@ -10,9 +13,31 @@ export const GET = async ({ url }) => { }); }; -export const PUT = async ({ url }) => { +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(Number(url.searchParams.get('id') || 0)), { + 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' } |