upd: api mobile revisi

This commit is contained in:
2026-02-23 14:37:26 +08:00
parent e62909b070
commit 0ed01d287f
6 changed files with 78 additions and 43 deletions

View File

@@ -227,12 +227,18 @@ export async function PUT(request: Request, context: { params: { id: string } })
export async function POST(request: Request, context: { params: { id: string } }) {
try {
const { id } = context.params
const body = await request.formData()
const dataBody = body.get("data")
const cekFile = body.has("file0")
const contentType = request.headers.get("content-type");
// const { title, desc, user } = (await request.json())
const { title, desc, user, oldFile } = JSON.parse(dataBody as string)
let title, desc, user, oldFile: any[] = [], cekFile, body: FormData | undefined
if (contentType?.includes("multipart/form-data")) {
body = await request.formData()
const dataBody = body.get("data")
cekFile = body.has("file0");
({ title, desc, user, oldFile } = JSON.parse(dataBody as string))
} else {
({ title, desc, user } = await request.json());
}
const userMobile = await funGetUserById({ id: String(user) })
@@ -273,7 +279,7 @@ export async function POST(request: Request, context: { params: { id: string } }
}
}
if (cekFile) {
if (cekFile && body) {
body.delete("data")
for (var pair of body.entries()) {
if (String(pair[0]).substring(0, 4) == "file") {