From 29e72d92d5908188001f6a0543bb7651f143c85b Mon Sep 17 00:00:00 2001 From: Fuwn Date: Thu, 15 Feb 2024 08:46:22 -0800 Subject: feat(hololive): stream pinning --- src/routes/api/configuration/pin/+server.ts | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/routes/api/configuration/pin/+server.ts (limited to 'src/routes/api/configuration/pin/+server.ts') diff --git a/src/routes/api/configuration/pin/+server.ts b/src/routes/api/configuration/pin/+server.ts new file mode 100644 index 00000000..f813d8e8 --- /dev/null +++ b/src/routes/api/configuration/pin/+server.ts @@ -0,0 +1,32 @@ +import { userIdentity } from '$lib/Data/AniList/identity'; +import { toggleHololiveStreamPinning } from '$lib/Database/userConfiguration'; + +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' + } + } + ); +}; -- cgit v1.2.3