mirror of
https://github.com/honojs/hono.git
synced 2024-11-30 01:56:18 +01:00
b567a574d6
* refactor: form body should be `Record<string, string | File>` * refactored
19 lines
483 B
TypeScript
19 lines
483 B
TypeScript
export type BodyData = Record<string, string | File>
|
|
|
|
export async function parseBody(r: Request | Response) {
|
|
let body: BodyData = {}
|
|
const contentType = r.headers.get('Content-Type')
|
|
if (
|
|
contentType &&
|
|
(contentType.startsWith('multipart/form-data') ||
|
|
contentType === 'application/x-www-form-urlencoded')
|
|
) {
|
|
const form: BodyData = {}
|
|
;(await r.formData()).forEach((value, key) => {
|
|
form[key] = value
|
|
})
|
|
body = form
|
|
}
|
|
return body
|
|
}
|