mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
fix(api): 🐛 Add JSON support to every form that doesn't have a file parameter
This commit is contained in:
parent
9f0eab03f2
commit
4713d0f93f
5 changed files with 12 additions and 6 deletions
|
|
@ -207,12 +207,16 @@ export const jsonOrForm = () => {
|
|||
context.req.parseBody = async <T extends BodyData = BodyData>() =>
|
||||
(await context.req.json()) as T;
|
||||
context.req.bodyCache.formData = await context.req.json();
|
||||
context.req.formData = async () =>
|
||||
context.req.bodyCache.formData as FormData;
|
||||
} else if (contentType?.includes("application/x-www-form-urlencoded")) {
|
||||
const parsed = parse(await context.req.text(), {
|
||||
parseArrays: true,
|
||||
interpretNumericEntities: true,
|
||||
});
|
||||
|
||||
context.req.parseBody = <T extends BodyData = BodyData>() =>
|
||||
Promise.resolve(parsed as T);
|
||||
// @ts-ignore Very bad hack
|
||||
context.req.formData = () => Promise.resolve(parsed);
|
||||
// @ts-ignore I'm so sorry for this
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue