Update index.ts
This commit is contained in:
+5
-1
@@ -75,10 +75,10 @@ export const app = new Elysia()
|
|||||||
// Error handling: Return status code and message
|
// Error handling: Return status code and message
|
||||||
.onError(({ error, status }) => {
|
.onError(({ error, status }) => {
|
||||||
if (error instanceof HttpError) {
|
if (error instanceof HttpError) {
|
||||||
|
console.error(`[-] HTTP ${error.status}: ${error.message}`)
|
||||||
if (error.content instanceof String) return status(error.status, { msg: error.message })
|
if (error.content instanceof String) return status(error.status, { msg: error.message })
|
||||||
else return status(error.status, error.content)
|
else return status(error.status, error.content)
|
||||||
}
|
}
|
||||||
// else return status(500, { error: "Internal Server Error" })
|
|
||||||
else throw error
|
else throw error
|
||||||
})
|
})
|
||||||
.get("/", ({ redirect }) => redirect("https://aza.moe/photo"))
|
.get("/", ({ redirect }) => redirect("https://aza.moe/photo"))
|
||||||
@@ -87,6 +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)
|
||||||
|
|
||||||
|
console.log("[+] Received upload request")
|
||||||
|
|
||||||
// Generate an ID of 8 numbers
|
// Generate an ID of 8 numbers
|
||||||
const id = Math.random().toString().substring(2, 10)
|
const id = Math.random().toString().substring(2, 10)
|
||||||
let metadata = await getMetadata()
|
let metadata = await getMetadata()
|
||||||
@@ -128,6 +130,8 @@ export const app = new Elysia()
|
|||||||
metadata.push(newEntry)
|
metadata.push(newEntry)
|
||||||
await saveMetadata(metadata)
|
await saveMetadata(metadata)
|
||||||
|
|
||||||
|
console.log(`[+] Upload complete for photo ${newEntry.id}`)
|
||||||
|
|
||||||
done(201, { success: true, id: newEntry.id })
|
done(201, { success: true, id: newEntry.id })
|
||||||
}, {
|
}, {
|
||||||
// --- Validation Schema ---
|
// --- Validation Schema ---
|
||||||
|
|||||||
Reference in New Issue
Block a user