import { listFiles, uploadFile } from '../../../../lib/disk.js';
export const dynamic='force-dynamic'; export const runtime='nodejs';
export async function GET(request){ const u=new URL(request.url); return Response.json({ files:listFiles({project_id:u.searchParams.get('project_id'), folder_id:u.searchParams.get('folder_id')}) }); }
export async function POST(request){ try{ const form=await request.formData(); const project_id=form.get('project_id'); const folder_id=form.get('folder_id') || null; const out=[]; for(const [key,value] of form.entries()){ if(key==='files' || value?.arrayBuffer){ const buf=Buffer.from(await value.arrayBuffer()); out.push(uploadFile(project_id, folder_id, { name:value.name, type:value.type, buffer:buf }, { local_only:form.get('local_only')==='true' })); } } return Response.json({ files:out },{status:201}); }catch(e){ return Response.json({error:e.message},{status:400}); } }
