aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-01-11 09:06:40 -0800
committerFuwn <[email protected]>2024-01-11 09:06:40 -0800
commitf28c9ad38d2102b589903f138ea03f03ca5507e9 (patch)
treed1388200e606ed2f23677e600a0491cc2296a11d
parentfeat(layout): page animations (diff)
downloaddue.moe-f28c9ad38d2102b589903f138ea03f03ca5507e9.tar.xz
due.moe-f28c9ad38d2102b589903f138ea03f03ca5507e9.zip
refactor(routes): move shortcuts to hooks
-rw-r--r--src/hooks.server.ts24
-rw-r--r--src/routes/birthdays/+server.ts12
-rw-r--r--src/routes/wrapped/+server.ts11
3 files changed, 23 insertions, 24 deletions
diff --git a/src/hooks.server.ts b/src/hooks.server.ts
index 48fc1f1b..d0f09b6e 100644
--- a/src/hooks.server.ts
+++ b/src/hooks.server.ts
@@ -1,4 +1,19 @@
-import type { Handle } from '@sveltejs/kit';
+import root from '$lib/Utility/root';
+import type { Handle, RequestEvent } from '@sveltejs/kit';
+
+const redirectWithParameters = (
+ event: RequestEvent<Partial<Record<string, string>>, string | null>,
+ path: string
+) => {
+ return Response.redirect(
+ root(
+ `${path}${
+ event.url.searchParams.toString().length > 0 ? `?${event.url.searchParams.toString()}` : ''
+ }`
+ ),
+ 307
+ );
+};
export const handle: Handle = async ({ event, resolve }) => {
const { cookies } = event;
@@ -15,5 +30,12 @@ export const handle: Handle = async ({ event, resolve }) => {
};
}
+ switch (event.url.pathname) {
+ case '/birthdays':
+ return redirectWithParameters(event, '/tools/birthdays');
+ case '/wrapped':
+ return redirectWithParameters(event, '/tools/wrapped');
+ }
+
return await resolve(event);
};
diff --git a/src/routes/birthdays/+server.ts b/src/routes/birthdays/+server.ts
deleted file mode 100644
index e20d6c8a..00000000
--- a/src/routes/birthdays/+server.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-import root from '$lib/Utility/root.js';
-
-export const GET = ({ url }) => {
- return Response.redirect(
- root(
- `/tools/birthdays${
- url.searchParams.toString().length > 0 ? `?${url.searchParams.toString()}` : ''
- }`
- ),
- 307
- );
-};
diff --git a/src/routes/wrapped/+server.ts b/src/routes/wrapped/+server.ts
deleted file mode 100644
index e9c8c8d2..00000000
--- a/src/routes/wrapped/+server.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-import root from '$lib/Utility/root.js';
-
-export const GET = ({ url }) =>
- Response.redirect(
- root(
- `/tools/wrapped${
- url.searchParams.toString().length > 0 ? `&${url.searchParams.toString()}` : ''
- }`
- ),
- 307
- );