Files
rednote-tool-studio/app/api/projects/[id]/files/[...path]/route.ts
T
2026-09-17 21:54:33 +08:00

25 lines
1.0 KiB
TypeScript

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); }
}