From c4267cce67e7de6dea2277ce07b6f9a22d8ca674 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Thu, 14 Dec 2023 12:52:26 -0800 Subject: feat(api): nest routes --- src/routes/+layout.svelte | 4 ++-- src/routes/api/anilist-increment/+server.ts | 27 ------------------------ src/routes/api/anilist/increment/+server.ts | 27 ++++++++++++++++++++++++ src/routes/api/authentication-log-out/+server.ts | 7 ------ src/routes/api/authentication/log-out/+server.ts | 7 ++++++ 5 files changed, 36 insertions(+), 36 deletions(-) delete mode 100644 src/routes/api/anilist-increment/+server.ts create mode 100644 src/routes/api/anilist/increment/+server.ts delete mode 100644 src/routes/api/authentication-log-out/+server.ts create mode 100644 src/routes/api/authentication/log-out/+server.ts (limited to 'src/routes') diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 2374ff8e..881e50f4 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -39,7 +39,7 @@ >Log in {:else} - Log out ({currentUserIdentity.name}) + Log out ({currentUserIdentity.name}) {/if} {:else} @@ -55,7 +55,7 @@ Log in with AniList {:else} - Log out from AniList ({currentUserIdentity.name}) + Log out from AniList ({currentUserIdentity.name}) {/if}

diff --git a/src/routes/api/anilist-increment/+server.ts b/src/routes/api/anilist-increment/+server.ts deleted file mode 100644 index 4680236b..00000000 --- a/src/routes/api/anilist-increment/+server.ts +++ /dev/null @@ -1,27 +0,0 @@ -export const GET = async ({ url, cookies }) => { - const userCookie = cookies.get('user'); - - if (!userCookie) { - return new Response('Unauthenticated', { status: 401 }); - } - - const user = JSON.parse(userCookie); - - return Response.json( - await ( - await fetch('https://graphql.anilist.co', { - method: 'POST', - headers: { - Authorization: `${user['token_type']} ${user['access_token']}`, - 'Content-Type': 'application/json', - Accept: 'application/json' - }, - body: JSON.stringify({ - query: `mutation { SaveMediaListEntry(mediaId: ${ - url.searchParams.get('id') || 'null' - }, progress: ${url.searchParams.get('progress') || 'null'}) { id } }` - }) - }) - ).json() - ); -}; diff --git a/src/routes/api/anilist/increment/+server.ts b/src/routes/api/anilist/increment/+server.ts new file mode 100644 index 00000000..4680236b --- /dev/null +++ b/src/routes/api/anilist/increment/+server.ts @@ -0,0 +1,27 @@ +export const GET = async ({ url, cookies }) => { + const userCookie = cookies.get('user'); + + if (!userCookie) { + return new Response('Unauthenticated', { status: 401 }); + } + + const user = JSON.parse(userCookie); + + return Response.json( + await ( + await fetch('https://graphql.anilist.co', { + method: 'POST', + headers: { + Authorization: `${user['token_type']} ${user['access_token']}`, + 'Content-Type': 'application/json', + Accept: 'application/json' + }, + body: JSON.stringify({ + query: `mutation { SaveMediaListEntry(mediaId: ${ + url.searchParams.get('id') || 'null' + }, progress: ${url.searchParams.get('progress') || 'null'}) { id } }` + }) + }) + ).json() + ); +}; diff --git a/src/routes/api/authentication-log-out/+server.ts b/src/routes/api/authentication-log-out/+server.ts deleted file mode 100644 index 22ef49d8..00000000 --- a/src/routes/api/authentication-log-out/+server.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { redirect } from '@sveltejs/kit'; - -export const GET = ({ cookies }) => { - cookies.delete('user', { path: '/' }); - - throw redirect(303, '/'); -}; diff --git a/src/routes/api/authentication/log-out/+server.ts b/src/routes/api/authentication/log-out/+server.ts new file mode 100644 index 00000000..22ef49d8 --- /dev/null +++ b/src/routes/api/authentication/log-out/+server.ts @@ -0,0 +1,7 @@ +import { redirect } from '@sveltejs/kit'; + +export const GET = ({ cookies }) => { + cookies.delete('user', { path: '/' }); + + throw redirect(303, '/'); +}; -- cgit v1.2.3