From 861c03b85160972431ca9b262345d15edecf9acb Mon Sep 17 00:00:00 2001 From: Fuwn Date: Tue, 24 Oct 2023 17:12:54 -0700 Subject: feat: badge wall --- src/routes/api/badges/remove/+server.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/routes/api/badges/remove/+server.ts (limited to 'src/routes/api/badges/remove/+server.ts') diff --git a/src/routes/api/badges/remove/+server.ts b/src/routes/api/badges/remove/+server.ts new file mode 100644 index 00000000..8b05369a --- /dev/null +++ b/src/routes/api/badges/remove/+server.ts @@ -0,0 +1,22 @@ +import { userIdentity } from '$lib/AniList/identity.js'; +import { removeUserBadge } from '$lib/userBadgesDatabase.js'; + +export const POST = async ({ url, cookies }) => { + const userCookie = cookies.get('user'); + + if (!userCookie) { + return new Response('Unauthenticated', { status: 401 }); + } + + const user = JSON.parse(userCookie); + const identity = await userIdentity({ + tokenType: user['token_type'], + expiresIn: user['expires_in'], + accessToken: user['access_token'], + refreshToken: user['refresh_token'] + }); + + removeUserBadge(identity.id, Number(url.searchParams.get('id'))); + + return Response.json({}); +}; -- cgit v1.2.3