Your Name e054dcabcc
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled
feat: update canvas and flow board features
2026-04-11 22:28:18 +08:00

117 lines
2.6 KiB
TypeScript

import { NextResponse } from "next/server";
import { auth } from "@/app/(auth)/auth";
import {
deleteFlowBoardDraftById,
getFlowBoardDraftById,
updateFlowBoardDraftById,
} from "@/lib/db/queries";
import {
mapFlowBoardDraft,
normalizeFlowBoardSnapshot,
normalizeFlowBoardTitle,
} from "../../_utils";
export const runtime = "nodejs";
export const dynamic = "force-dynamic";
export const revalidate = 0;
type RouteContext = {
params: Promise<{ id: string }>;
};
export async function GET(_request: Request, { params }: RouteContext) {
const session = await auth();
if (!session?.user?.id) {
return NextResponse.json(
{ success: false, error: "未登录" },
{ status: 401 }
);
}
const { id } = await params;
const draft = await getFlowBoardDraftById({
userId: session.user.id,
draftId: id,
});
if (!draft) {
return NextResponse.json(
{ success: false, error: "流程白板文件不存在" },
{ status: 404 }
);
}
return NextResponse.json({
success: true,
data: mapFlowBoardDraft(draft),
});
}
export async function PUT(request: Request, { params }: RouteContext) {
const session = await auth();
if (!session?.user?.id) {
return NextResponse.json(
{ success: false, error: "未登录" },
{ status: 401 }
);
}
const { id } = await params;
const body = (await request.json().catch(() => ({}))) as {
title?: unknown;
snapshot?: unknown;
};
const draft = await updateFlowBoardDraftById({
userId: session.user.id,
draftId: id,
title:
body.title !== undefined
? normalizeFlowBoardTitle(body.title)
: undefined,
snapshot:
body.snapshot !== undefined
? normalizeFlowBoardSnapshot(body.snapshot)
: undefined,
});
if (!draft) {
return NextResponse.json(
{ success: false, error: "流程白板文件不存在" },
{ status: 404 }
);
}
return NextResponse.json({
success: true,
data: mapFlowBoardDraft(draft),
});
}
export async function DELETE(_request: Request, { params }: RouteContext) {
const session = await auth();
if (!session?.user?.id) {
return NextResponse.json(
{ success: false, error: "未登录" },
{ status: 401 }
);
}
const { id } = await params;
const draft = await deleteFlowBoardDraftById({
userId: session.user.id,
draftId: id,
});
if (!draft) {
return NextResponse.json(
{ success: false, error: "流程白板文件不存在" },
{ status: 404 }
);
}
return NextResponse.json({
success: true,
data: mapFlowBoardDraft(draft),
});
}