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
|
const { owner_key, photo, edited_photo } = body
|
||||||
checkHeaderKey(headers)
|
checkHeaderKey(headers)
|
||||||
|
|
||||||
// Generate an ID of 8 characters
|
// Generate an ID of 8 numbers
|
||||||
const id = Math.random().toString(36).substring(2, 10)
|
const id = Math.random().toString().substring(2, 10)
|
||||||
let metadata = await getMetadata()
|
let metadata = await getMetadata()
|
||||||
|
|
||||||
// Process and save files
|
// 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
|
// Redirect for short links. ID can be either ID or owner_key
|
||||||
.get("/:id", async ({ params, redirect }) => {
|
.get("/:idOrKey", async ({ params, redirect }) => {
|
||||||
const { id } = params
|
const { idOrKey } = params
|
||||||
const metadata = await getMetadata()
|
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 || 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}`)
|
return redirect(`https://aza.moe/photo/${photo.id}`)
|
||||||
}, {
|
}, {
|
||||||
params: t.Object({ id: t.String() })
|
params: t.Object({ idOrKey: t.String() })
|
||||||
})
|
})
|
||||||
|
|
||||||
.listen(3000)
|
.listen(3000)
|
||||||
|
|||||||
Reference in New Issue
Block a user