[+] Upload

This commit is contained in:
2025-10-26 12:31:16 +08:00
parent 5fbacee18f
commit 6f2037a9dc
4 changed files with 86 additions and 9 deletions
+5 -2
View File
@@ -72,7 +72,7 @@ async function getExifData(file: File): Promise<any> {
const INSTANT_KEY = process.env.INSTANT_KEY!
if (!await exists(FOLDER_PHOTOS)) await mkdir(FOLDER_PHOTOS, { recursive: true })
console.log("Server starting with valid 'secrets.json'.")
console.log("Server started.")
function checkHeaderKey(headers: Record<string, string | undefined>, expectList: string[] = [INSTANT_KEY]) {
const key = headers["x-instant-key"]
@@ -80,13 +80,16 @@ function checkHeaderKey(headers: Record<string, string | undefined>, expectList:
}
export const app = new Elysia()
.get("/", () => "Running!")
// Error handling: Return status code and message
.onError(({ error, status }) => {
if (error instanceof HttpError) {
if (error.content instanceof String) return status(error.status, { msg: error.message })
else return status(error.status, error.content)
}
else return status(500, { error: "Internal Server Error" })
// else return status(500, { error: "Internal Server Error" })
else throw error
})
.post("/upload", async ({ body, headers, status }) => {