scrape / app /api /project /route.ts
kjbytes's picture
push code
ef4c36f
Raw
History Blame Contribute Delete
1.41 kB
import { NextRequest, NextResponse } from "next/server";
import { loadProject, saveProject } from "@/lib/storage";
import type { Project } from "@/types";
export const runtime = "nodejs";
export async function GET(req: NextRequest) {
const id = req.nextUrl.searchParams.get("id");
if (!id) return NextResponse.json({ error: "Missing id" }, { status: 400 });
const project = await loadProject(id);
if (!project) return NextResponse.json({ error: "Project not found" }, { status: 404 });
return NextResponse.json(project);
}
export async function PUT(req: NextRequest) {
try {
const body = (await req.json()) as Project;
if (!body?.id) return NextResponse.json({ error: "Missing project id" }, { status: 400 });
const existing = await loadProject(body.id);
if (!existing) return NextResponse.json({ error: "Project not found" }, { status: 404 });
const updated: Project = {
...existing,
captions: body.captions ?? existing.captions,
style: body.style ?? existing.style,
layout: body.layout ?? existing.layout,
animation: body.animation ?? existing.animation,
status: body.status ?? existing.status,
};
await saveProject(updated);
return NextResponse.json(updated);
} catch (error) {
return NextResponse.json(
{ error: error instanceof Error ? error.message : "Save failed" },
{ status: 500 },
);
}
}