- 为 documents.save/meta/content、blocks.patch 与 sidebar.dataset.list 补齐 Rust 协议映射、共享契约与桥接执行器 - 对齐 BlockNote、Mindmap、OnlyOffice 的保存/路由元信息,并补真实浏览器回归脚本与 OnlyOffice 部署基线 - 忽略 Rust 本地构建产物与 Harness 调试状态文件,避免临时产物进入仓库历史
101 lines
3.0 KiB
TypeScript
101 lines
3.0 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import { isConvexEnabled } from "@/lib/convex/enabled";
|
|
import { getAuthedConvexClient } from "@/lib/convex/route";
|
|
import { api } from "@/lib/convex/api";
|
|
import { buildMindmapRouteMeta } from "@/lib/mindmap/mindmapRouteMeta";
|
|
|
|
const defaultMindmapData = {
|
|
data: { text: "中心主题" },
|
|
children: [],
|
|
};
|
|
|
|
export async function GET(
|
|
request: Request,
|
|
{ params }: { params: Promise<{ docId: string }> },
|
|
) {
|
|
const { docId } = await params;
|
|
|
|
if (isConvexEnabled()) {
|
|
const { auth, client } = await getAuthedConvexClient();
|
|
const mindmapId = `legacy-${docId}`;
|
|
const res = await client.query(api.mindmaps.get, { docId, mindmapId });
|
|
return NextResponse.json({
|
|
data: res?.data ?? defaultMindmapData,
|
|
source: "convex",
|
|
meta: {
|
|
...buildMindmapRouteMeta(request, {
|
|
workspaceId: res?.meta?.workspace_id ?? null,
|
|
documentId: docId,
|
|
mindmapId,
|
|
ownerUserId: auth.userId,
|
|
}),
|
|
exists: Boolean(res?.meta?.exists),
|
|
deletedAt: res?.meta?.deleted_at ?? null,
|
|
createdAt: res?.meta?.created_at ?? null,
|
|
updatedAt: res?.meta?.updated_at ?? null,
|
|
},
|
|
});
|
|
}
|
|
|
|
return NextResponse.json({ error: "当前仅支持 Convex 模式" }, { status: 501 });
|
|
}
|
|
|
|
export async function POST(
|
|
request: Request,
|
|
{ params }: { params: Promise<{ docId: string }> },
|
|
) {
|
|
const { docId } = await params;
|
|
|
|
if (isConvexEnabled()) {
|
|
const { auth, client } = await getAuthedConvexClient();
|
|
const mindmapId = `legacy-${docId}`;
|
|
const payload = (await request.json().catch(() => ({}))) as { data?: unknown };
|
|
const result = await client.mutation(api.mindmaps.put, {
|
|
docId,
|
|
mindmapId,
|
|
data: payload.data ?? defaultMindmapData,
|
|
});
|
|
return NextResponse.json({
|
|
...(result ?? { ok: true }),
|
|
meta: {
|
|
...buildMindmapRouteMeta(request, {
|
|
workspaceId: result?.workspace_id ?? null,
|
|
documentId: docId,
|
|
mindmapId,
|
|
ownerUserId: auth.userId,
|
|
}),
|
|
updatedAt: result?.updated_at ?? null,
|
|
},
|
|
});
|
|
}
|
|
|
|
return NextResponse.json({ error: "当前仅支持 Convex 模式" }, { status: 501 });
|
|
}
|
|
|
|
export async function DELETE(
|
|
request: Request,
|
|
{ params }: { params: Promise<{ docId: string }> },
|
|
) {
|
|
const { docId } = await params;
|
|
|
|
if (isConvexEnabled()) {
|
|
const { auth, client } = await getAuthedConvexClient();
|
|
const mindmapId = `legacy-${docId}`;
|
|
const result = await client.mutation(api.mindmaps.softDelete, { docId, mindmapId });
|
|
return NextResponse.json({
|
|
...(result ?? { ok: true }),
|
|
meta: {
|
|
...buildMindmapRouteMeta(request, {
|
|
workspaceId: result?.workspace_id ?? null,
|
|
documentId: docId,
|
|
mindmapId,
|
|
ownerUserId: auth.userId,
|
|
}),
|
|
deletedAt: result?.deleted_at ?? null,
|
|
},
|
|
});
|
|
}
|
|
|
|
return NextResponse.json({ error: "当前仅支持 Convex 模式" }, { status: 501 });
|
|
}
|