diff options
Diffstat (limited to 'src/routes/api/configuration/+server.ts')
| -rw-r--r-- | src/routes/api/configuration/+server.ts | 111 |
1 files changed, 57 insertions, 54 deletions
diff --git a/src/routes/api/configuration/+server.ts b/src/routes/api/configuration/+server.ts index 41a70f7b..10b6b09f 100644 --- a/src/routes/api/configuration/+server.ts +++ b/src/routes/api/configuration/+server.ts @@ -1,70 +1,73 @@ -import { userIdentity } from '$lib/Data/AniList/identity'; +import { userIdentity } from "$lib/Data/AniList/identity"; import { - deleteUserConfiguration, - getUserConfiguration, - setUserConfiguration -} from '$lib/Database/SB/User/configuration'; + deleteUserConfiguration, + getUserConfiguration, + setUserConfiguration, +} from "$lib/Database/SB/User/configuration"; -const unauthorised = new Response('Unauthorised', { status: 401 }); +const unauthorised = new Response("Unauthorised", { status: 401 }); export const GET = async ({ url }) => - Response.json(await getUserConfiguration(Number(url.searchParams.get('id') || 0)), { - headers: { - 'Access-Control-Allow-Origin': 'https://due.moe' - } - }); + Response.json( + await getUserConfiguration(Number(url.searchParams.get("id") || 0)), + { + headers: { + "Access-Control-Allow-Origin": "https://due.moe", + }, + }, + ); export const PUT = async ({ cookies, request }) => { - const userCookie = cookies.get('user'); + const userCookie = cookies.get("user"); - if (!userCookie) return unauthorised; + if (!userCookie) return unauthorised; - const user = JSON.parse(userCookie); + const user = JSON.parse(userCookie); - return Response.json( - await setUserConfiguration( - ( - await userIdentity({ - tokenType: user['token_type'], - expiresIn: user['expires_in'], - accessToken: user['access_token'], - refreshToken: user['refresh_token'] - }) - ).id, - { - configuration: await request.json() - } - ), - { - headers: { - 'Access-Control-Allow-Origin': 'https://due.moe' - } - } - ); + return Response.json( + await setUserConfiguration( + ( + await userIdentity({ + tokenType: user["token_type"], + expiresIn: user["expires_in"], + accessToken: user["access_token"], + refreshToken: user["refresh_token"], + }) + ).id, + { + configuration: await request.json(), + }, + ), + { + headers: { + "Access-Control-Allow-Origin": "https://due.moe", + }, + }, + ); }; export const DELETE = async ({ cookies }) => { - const userCookie = cookies.get('user'); + const userCookie = cookies.get("user"); - if (!userCookie) return unauthorised; + if (!userCookie) return unauthorised; - const user = JSON.parse(userCookie); + const user = JSON.parse(userCookie); - return Response.json( - await deleteUserConfiguration( - ( - await userIdentity({ - tokenType: user['token_type'], - expiresIn: user['expires_in'], - accessToken: user['access_token'], - refreshToken: user['refresh_token'] - }) - ).id - ), - { - headers: { - 'Access-Control-Allow-Origin': 'https://due.moe' - } - } - ); + return Response.json( + await deleteUserConfiguration( + ( + await userIdentity({ + tokenType: user["token_type"], + expiresIn: user["expires_in"], + accessToken: user["access_token"], + refreshToken: user["refresh_token"], + }) + ).id, + ), + { + headers: { + "Access-Control-Allow-Origin": "https://due.moe", + }, + }, + ); }; |