38 lines
1.6 KiB
TypeScript
38 lines
1.6 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import { z } from "zod";
|
|
import { and, eq } from "drizzle-orm";
|
|
import { auth } from "@/app/(auth)/auth";
|
|
import { db } from "@/lib/db";
|
|
import { canvasProject } from "@/lib/db/schema";
|
|
import { getSystemSetting } from "@/lib/db/queries";
|
|
import {
|
|
normalizeVideoCanvasFunctionConfig,
|
|
VIDEO_CANVAS_FUNCTION_CONFIG_KEY,
|
|
} from "@/lib/video-canvas/config";
|
|
import { getCanvasAgentAccessManifest } from "@/lib/ai/canvas-agent-runtime/capability-access";
|
|
export const dynamic = "force-dynamic";
|
|
export async function GET(request: Request) {
|
|
const session = await auth();
|
|
if (!session?.user?.id) return NextResponse.json({ error: "未登录" }, { status: 401 });
|
|
const parsed = z.string().uuid().safeParse(new URL(request.url).searchParams.get("projectId"));
|
|
if (!parsed.success) return NextResponse.json({ error: "画布编号无效" }, { status: 400 });
|
|
const [project] = await db
|
|
.select({ id: canvasProject.id, workspace: canvasProject.workspaceType })
|
|
.from(canvasProject)
|
|
.where(and(eq(canvasProject.id, parsed.data), eq(canvasProject.userId, session.user.id)))
|
|
.limit(1);
|
|
if (!project) return NextResponse.json({ error: "画布不存在" }, { status: 404 });
|
|
const config = normalizeVideoCanvasFunctionConfig(
|
|
(await getSystemSetting({ key: VIDEO_CANVAS_FUNCTION_CONFIG_KEY }))?.value,
|
|
);
|
|
return NextResponse.json(
|
|
{
|
|
workspace: project.workspace,
|
|
capabilities: getCanvasAgentAccessManifest(config).filter(
|
|
(item) => item.workspace === (project.workspace === "video" ? "video" : "canvas"),
|
|
),
|
|
},
|
|
{ headers: { "Cache-Control": "private, no-store" } },
|
|
);
|
|
}
|