- 为 documents.save/meta/content、blocks.patch 与 sidebar.dataset.list 补齐 Rust 协议映射、共享契约与桥接执行器 - 对齐 BlockNote、Mindmap、OnlyOffice 的保存/路由元信息,并补真实浏览器回归脚本与 OnlyOffice 部署基线 - 忽略 Rust 本地构建产物与 Harness 调试状态文件,避免临时产物进入仓库历史
68 lines
2.1 KiB
TypeScript
68 lines
2.1 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 {
|
|
assertDocumentId,
|
|
buildDocumentBridgeContext,
|
|
buildDocumentQueryEnvelope,
|
|
documentBridgeErrorResponse,
|
|
} from "@/lib/documents/bridge";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
export async function GET(request: Request) {
|
|
if (isConvexEnabled()) {
|
|
try {
|
|
const url = new URL(request.url);
|
|
const documentId = assertDocumentId(url.searchParams.get("documentId"));
|
|
const workspaceId = url.searchParams.get("workspaceId")?.trim() || null;
|
|
const { client } = await getAuthedConvexClient();
|
|
const bridgeContext = await buildDocumentBridgeContext({ request, workspaceId });
|
|
const envelope = buildDocumentQueryEnvelope({
|
|
name: "documents.content.get",
|
|
payload: { documentId, workspaceId },
|
|
});
|
|
|
|
const result = await client.query(api.documents.getContent, {
|
|
id: documentId,
|
|
});
|
|
|
|
if (!result) {
|
|
return NextResponse.json(
|
|
{
|
|
error: "页面不存在",
|
|
meta: {
|
|
requestId: bridgeContext.requestId,
|
|
traceId: bridgeContext.traceId,
|
|
queryName: envelope.name,
|
|
},
|
|
},
|
|
{ status: 404 },
|
|
);
|
|
}
|
|
|
|
return NextResponse.json({
|
|
content: result.content ?? null,
|
|
revision:
|
|
typeof result.revision === "number" && Number.isInteger(result.revision)
|
|
? result.revision
|
|
: 0,
|
|
conflictDetectionKey:
|
|
typeof result.conflict_detection_key === "string" && result.conflict_detection_key.trim()
|
|
? result.conflict_detection_key
|
|
: `${documentId}:0`,
|
|
meta: {
|
|
requestId: bridgeContext.requestId,
|
|
traceId: bridgeContext.traceId,
|
|
queryName: envelope.name,
|
|
},
|
|
});
|
|
} catch (error) {
|
|
return documentBridgeErrorResponse(error);
|
|
}
|
|
}
|
|
|
|
return NextResponse.json({ error: "当前仅支持 Convex 模式" }, { status: 501 });
|
|
}
|