fix: local pin POST body lezing - lees als text voordat JSON parse

This commit is contained in:
maikrolf
2026-09-19 17:15:02 +02:00
parent c64ca2b8c2
commit b67e735e04
+5 -2
View File
@@ -106,12 +106,15 @@ async function handleLocalPins(path: string, method: string, req: NextRequest):
// POST /api/pins — pin een CID // POST /api/pins — pin een CID
if (p === 'pins' && method === 'POST') { if (p === 'pins' && method === 'POST') {
try { try {
const body = await req.json(); // Lees body als text, dan parse als JSON (voorkomt "body already read" issues)
const text = await req.text();
const body = text ? JSON.parse(text) : {};
const { cid, name, size } = body; const { cid, name, size } = body;
if (!cid) return NextResponse.json({ error: 'cid required' }, { status: 400 }); if (!cid) return NextResponse.json({ error: 'cid required' }, { status: 400 });
await localAddPin(cid, name, size || 0); await localAddPin(cid, name, size || 0);
return NextResponse.json({ cid }); return NextResponse.json({ cid });
} catch { } catch (e) {
console.error('[handleLocalPins] POST error:', e);
return NextResponse.json({ error: 'Invalid request' }, { status: 400 }); return NextResponse.json({ error: 'Invalid request' }, { status: 400 });
} }
} }