54 lines
1.7 KiB
TypeScript
54 lines
1.7 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 { buildDocumentBridgeContextWithActor } from "@/lib/documents/bridge";
|
|
import { executeRustBridgeTool } from "@/lib/documents/rust-runtime";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
interface EmptyTrashPayload {
|
|
workspaceId?: string;
|
|
}
|
|
|
|
export async function POST(request: Request) {
|
|
if (isConvexEnabled()) {
|
|
const { client } = await getAuthedConvexClient();
|
|
const { workspaceId }: EmptyTrashPayload = await request.json().catch(() => ({}));
|
|
if (!workspaceId) {
|
|
return NextResponse.json({ error: "缺少 workspaceId" }, { status: 400 });
|
|
}
|
|
|
|
const context = buildDocumentBridgeContextWithActor({
|
|
request,
|
|
actor: {
|
|
actorType: "service",
|
|
actorId: "mindmap-trash-empty",
|
|
sessionId: null,
|
|
},
|
|
workspaceId,
|
|
source: {
|
|
channel: "mindmap-trash-route",
|
|
client: "wolai-frontend",
|
|
},
|
|
});
|
|
await executeRustBridgeTool({
|
|
context,
|
|
toolName: "mindmap_empty_trash",
|
|
invocationKind: "command",
|
|
args: { workspaceId },
|
|
data: { workspaceId, source: "mindmap-trash-empty" },
|
|
mode: "result",
|
|
});
|
|
|
|
try {
|
|
const result = await client.mutation(api.mindmaps.emptyTrashByWorkspace, { workspaceId });
|
|
return NextResponse.json({ ok: true, removed: result?.deletedCount ?? 0 });
|
|
} catch (error) {
|
|
return NextResponse.json({ error: (error as Error).message }, { status: 400 });
|
|
}
|
|
}
|
|
|
|
return NextResponse.json({ error: "当前仅支持 Convex 模式" }, { status: 501 });
|
|
}
|