diff options
| author | Fuwn <[email protected]> | 2024-02-15 08:46:22 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-02-15 08:46:22 -0800 |
| commit | 29e72d92d5908188001f6a0543bb7651f143c85b (patch) | |
| tree | f363504d7537e8bec905cf3a03afbfc350c1c1f0 /src/routes/api/configuration | |
| parent | feat(pwa): shortcuts (diff) | |
| download | due.moe-29e72d92d5908188001f6a0543bb7651f143c85b.tar.xz due.moe-29e72d92d5908188001f6a0543bb7651f143c85b.zip | |
feat(hololive): stream pinning
Diffstat (limited to 'src/routes/api/configuration')
| -rw-r--r-- | src/routes/api/configuration/pin/+server.ts | 32 |
1 files changed, 32 insertions, 0 deletions
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' + } + } + ); +}; |