Your Name c7ffcda87b
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled
feat: add infinite canvas feature with AI image generation
- Add canvas project and node database tables
- Create canvas workspace with drag, resize, zoom and pan
- Add ImageNode with background removal, enhance, extend, angle edit, scene fusion
- Add VideoNode with playback controls
- Add TextNode for text editing
- Integrate AI image generation API (Gemini/Alibaba)
- Implement viewport culling for performance optimization
- Add canvas entry in top navigation bar
2026-01-24 19:48:13 +08:00

59 lines
1.8 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server';
import { auth } from '@/app/(auth)/auth';
import { db } from '@/lib/db';
import { canvasProject } from '@/lib/db/schema';
import { eq, desc } from 'drizzle-orm';
// 获取画布列表
export async function GET(request: NextRequest) {
try {
const session = await auth();
if (!session?.user?.id) {
return NextResponse.json({ success: false, error: '未登录' }, { status: 401 });
}
const projects = await db
.select()
.from(canvasProject)
.where(eq(canvasProject.userId, session.user.id))
.orderBy(desc(canvasProject.updatedAt));
return NextResponse.json({ success: true, data: projects });
} catch (error) {
console.error('获取画布列表失败:', error);
return NextResponse.json({ success: false, error: '获取画布列表失败' }, { status: 500 });
}
}
// 创建画布
export async function POST(request: NextRequest) {
try {
const session = await auth();
if (!session?.user?.id) {
return NextResponse.json({ success: false, error: '未登录' }, { status: 401 });
}
const body = await request.json();
const { title, description, canvasData } = body;
const [newProject] = await db
.insert(canvasProject)
.values({
userId: session.user.id,
title: title || '未命名画布',
description,
canvasData: canvasData || {
nodes: [],
edges: [],
viewport: { x: 0, y: 0, zoom: 1 },
},
})
.returning();
return NextResponse.json({ success: true, data: newProject });
} catch (error) {
console.error('创建画布失败:', error);
return NextResponse.json({ success: false, error: '创建画布失败' }, { status: 500 });
}
}