Update index.ts
This commit is contained in:
+7
-6
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user