2025-11-23 10:55:04 +08:00
|
|
|
import { NextResponse } from "next/server";
|
2026-01-17 10:12:53 +08:00
|
|
|
import { isConvexEnabled } from "@/lib/convex/enabled";
|
2026-01-18 19:01:31 +08:00
|
|
|
import { getAuthedConvexClient } from "@/lib/convex/route";
|
2026-01-17 10:12:53 +08:00
|
|
|
import { api } from "@/lib/convex/api";
|
2025-11-23 10:55:04 +08:00
|
|
|
|
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
|
|
|
|
|
|
export async function POST(request: Request) {
|
2026-01-17 10:12:53 +08:00
|
|
|
if (isConvexEnabled()) {
|
2026-01-18 19:01:31 +08:00
|
|
|
const { client } = await getAuthedConvexClient();
|
2026-01-17 10:12:53 +08:00
|
|
|
const payload = await request.json().catch(() => ({}));
|
|
|
|
|
const workspaceId = payload.workspaceId as string | undefined;
|
|
|
|
|
if (!workspaceId) {
|
|
|
|
|
return NextResponse.json({ error: "缺少 workspaceId" }, { status: 400 });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await client.mutation(api.workspaces.switchDefaultWorkspace, {
|
|
|
|
|
workspaceId,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return NextResponse.json({ success: true });
|
|
|
|
|
}
|
2026-01-18 19:01:31 +08:00
|
|
|
return NextResponse.json({ error: "仅支持 Convex 模式" }, { status: 501 });
|
2025-11-23 10:55:04 +08:00
|
|
|
}
|