import { NextRequest, NextResponse } from "next/server"; import { errorResponse } from "../../../../../../lib/http"; import { readProjectFile, writeProjectFiles } from "../../../../../../lib/storage"; export const runtime = "nodejs"; type Context = { params: Promise<{ id: string; path: string[] }> }; export async function GET(_: NextRequest, context: Context) { try { const params = await context.params; return NextResponse.json({ content: await readProjectFile(params.id, params.path) }); } catch (error) { return errorResponse(error); } } export async function PUT(request: NextRequest, context: Context) { try { const params = await context.params; const body = await request.json(); if (typeof body.content !== "string") throw new Error("content must be a string"); const project = await writeProjectFiles(params.id, [{ path: params.path.join("/"), content: body.content }], body.revision); return NextResponse.json({ project }); } catch (error) { return errorResponse(error); } }