4-10 树域 Rust 家族化

This commit is contained in:
lix-2026
2026-04-24 06:10:18 +08:00
parent 41e958769e
commit 94631f3636
49 changed files with 5751 additions and 557 deletions
@@ -17,15 +17,60 @@ interface RenamePayload {
documentId: string;
workspaceId?: string | null;
title: string;
commandName?: string | null;
}
type TreeRenameResponse = {
requestId?: string;
traceId?: string;
};
export async function POST(request: Request) {
if (isConvexEnabled()) {
try {
const { documentId, workspaceId, title }: RenamePayload = await request.json();
const { documentId, workspaceId, title, commandName }: RenamePayload = await request.json();
const normalizedDocumentId = assertDocumentId(documentId);
const normalizedTitle = assertTitle(title);
const normalizedWorkspaceId = workspaceId?.trim() || null;
if (commandName !== PAGE_COMMAND_NAMES.updateTitle) {
const upstreamUrl = new URL("/api/tree/commands", request.url);
const response = await fetch(upstreamUrl.toString(), {
method: "POST",
headers: new Headers({
"content-type": "application/json",
}),
body: JSON.stringify({
action: "rename",
documentId: normalizedDocumentId,
workspaceId: normalizedWorkspaceId,
title: normalizedTitle,
}),
});
const payload = (await response.json().catch(() => null)) as TreeRenameResponse | { error?: string } | null;
if (!response.ok) {
return NextResponse.json(
{
error:
payload && typeof payload === "object" && "error" in payload && typeof payload.error === "string"
? payload.error
: "重命名失败,请稍后再试",
},
{ status: response.status },
);
}
return NextResponse.json({
ok: true,
meta: {
requestId: payload?.requestId,
traceId: payload?.traceId,
commandName: "tree.node.rename",
},
});
}
const bridgeContext = await buildDocumentBridgeContext({ request, workspaceId: normalizedWorkspaceId });
const envelope = buildDocumentCommandEnvelope({
name: PAGE_COMMAND_NAMES.updateTitle,