From a4be42d76918dc6fc27bcd9f7a78cea4a4c0a756 Mon Sep 17 00:00:00 2001 From: CancerAi Date: Wed, 23 Sep 2026 20:28:48 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E6=96=B0=E5=A2=9E=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E6=96=87=E4=BB=B6api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/index.ts b/src/index.ts index 7f18384..3aea9ca 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,6 +5,7 @@ import { postJson } from "./service/postJson"; import { isEmpty } from "./utils/is_empty"; import { get } from "./service/get"; import { cors } from "hono/cors"; +import { bodyLimit } from "hono/body-limit"; const tmpApp: Hono = new Hono() export const app = tmpApp.basePath("/test/") @@ -71,6 +72,29 @@ app.delete("/user", } ) +app.post("/file", + bodyLimit({ + maxSize: 5 * 1024 * 1024, + onError: (c) => { + return c.json(ApiResponse.err(400, "File must less than 5MB")) + } + }), + async (c) => { + const body = await c.req.parseBody() + const file = body["file"] + if (!(file instanceof File)) { + return c.json(ApiResponse.err(400, "Not file")) + } + + const fileName = file.name + const fileSize = file.size + return c.json(ApiResponse.success(200, "Upload file successfully", { + fileName, + fileSize + })) + } +) + app.notFound((c) => { console.log(`Not found [${c.req.method}]: ${c.req.path}`); return c.json(ApiResponse.err(404, "Not Found"))