From 2847ec14cd247b68c71bcb8f20fea08ce22aafc4 Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Sun, 26 Oct 2025 17:17:49 +0800 Subject: [PATCH] Update index.ts --- src/index.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/index.ts b/src/index.ts index f3f0d7c..b006394 100644 --- a/src/index.ts +++ b/src/index.ts @@ -87,8 +87,8 @@ export const app = new Elysia() const { owner_key, photo, edited_photo } = body checkHeaderKey(headers) - // Generate an ID of 8 characters - const id = Math.random().toString(36).substring(2, 10) + // Generate an ID of 8 numbers + const id = Math.random().toString().substring(2, 10) let metadata = await getMetadata() // Process and save files @@ -207,16 +207,17 @@ export const app = new Elysia() }) // Redirect for short links. ID can be either ID or owner_key - .get("/:id", async ({ params, redirect }) => { - const { id } = params + .get("/:idOrKey", async ({ params, redirect }) => { + const { idOrKey } = params const metadata = await getMetadata() - const photo = metadata.find((p) => p.id === id) || metadata.find((p) => p.owner_key === id) + const photo = metadata.find((p) => p.id === idOrKey) || metadata.find((p) => p.owner_key === idOrKey) if (!photo || photo.hide === true) done(404, "Photo not found") + if (photo.id != idOrKey) return redirect(`https://aza.moe/photo/${photo.id}?owner_key=${idOrKey}`) return redirect(`https://aza.moe/photo/${photo.id}`) }, { - params: t.Object({ id: t.String() }) + params: t.Object({ idOrKey: t.String() }) }) .listen(3000)