Your Name c7ffcda87b 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

117 lines
3.3 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, and } from 'drizzle-orm';
// 获取单个画布
export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const session = await auth();
if (!session?.user?.id) {
return NextResponse.json({ success: false, error: '未登录' }, { status: 401 });
}
const { id } = await params;
const [project] = await db
.select()
.from(canvasProject)
.where(
and(
eq(canvasProject.id, id),
eq(canvasProject.userId, session.user.id)
)
);
if (!project) {
return NextResponse.json({ success: false, error: '画布不存在' }, { status: 404 });
}
return NextResponse.json({ success: true, data: project });
} catch (error) {
console.error('获取画布失败:', error);
return NextResponse.json({ success: false, error: '获取画布失败' }, { status: 500 });
}
}
// 更新画布
export async function PUT(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const session = await auth();
if (!session?.user?.id) {
return NextResponse.json({ success: false, error: '未登录' }, { status: 401 });
}
const { id } = await params;
const body = await request.json();
const { title, description, thumbnail, canvasData } = body;
const updateData: any = { updatedAt: new Date() };
if (title !== undefined) updateData.title = title;
if (description !== undefined) updateData.description = description;
if (thumbnail !== undefined) updateData.thumbnail = thumbnail;
if (canvasData !== undefined) updateData.canvasData = canvasData;
const [updatedProject] = await db
.update(canvasProject)
.set(updateData)
.where(
and(
eq(canvasProject.id, id),
eq(canvasProject.userId, session.user.id)
)
)
.returning();
if (!updatedProject) {
return NextResponse.json({ success: false, error: '画布不存在' }, { status: 404 });
}
return NextResponse.json({ success: true, data: updatedProject });
} catch (error) {
console.error('更新画布失败:', error);
return NextResponse.json({ success: false, error: '更新画布失败' }, { status: 500 });
}
}
// 删除画布
export async function DELETE(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const session = await auth();
if (!session?.user?.id) {
return NextResponse.json({ success: false, error: '未登录' }, { status: 401 });
}
const { id } = await params;
const [deletedProject] = await db
.delete(canvasProject)
.where(
and(
eq(canvasProject.id, id),
eq(canvasProject.userId, session.user.id)
)
)
.returning();
if (!deletedProject) {
return NextResponse.json({ success: false, error: '画布不存在' }, { status: 404 });
}
return NextResponse.json({ success: true, data: deletedProject });
} catch (error) {
console.error('删除画布失败:', error);
return NextResponse.json({ success: false, error: '删除画布失败' }, { status: 500 });
}
}