v0.11.1: 权限体系重构 + AI管线优化 + 内容整理

This commit is contained in:
sgp
2026-05-22 18:36:41 +08:00
parent 7955d11c52
commit b33fe1e8e1
397 changed files with 30940 additions and 161 deletions
@@ -0,0 +1,76 @@
import { prisma } from "@/lib/prisma";
import { getServerSession } from "next-auth";
import { authOptions } from "@/lib/auth";
import { NextResponse } from "next/server";
export async function PUT(
request: Request,
{ params }: { params: { id: string } }
) {
const session = await getServerSession(authOptions);
if (!session?.user?.id) {
return NextResponse.json({ error: "请先登录" }, { status: 401 });
}
const collectionId = parseInt(params.id);
const userId = parseInt(session.user.id);
const existing = await prisma.collection.findUnique({
where: { id: collectionId },
});
if (!existing || existing.userId !== userId) {
return NextResponse.json({ error: "收藏夹不存在或无权限" }, { status: 403 });
}
const body = await request.json();
const { name, description } = body;
const data: any = {};
if (name !== undefined) {
if (!name.trim()) {
return NextResponse.json({ error: "名称不能为空" }, { status: 400 });
}
if (name.trim().length > 50) {
return NextResponse.json({ error: "名称不能超过50个字符" }, { status: 400 });
}
data.name = name.trim();
}
if (description !== undefined) {
data.description = description?.trim() || null;
}
const collection = await prisma.collection.update({
where: { id: collectionId },
data,
});
return NextResponse.json(collection);
}
export async function DELETE(
_request: Request,
{ params }: { params: { id: string } }
) {
const session = await getServerSession(authOptions);
if (!session?.user?.id) {
return NextResponse.json({ error: "请先登录" }, { status: 401 });
}
const collectionId = parseInt(params.id);
const userId = parseInt(session.user.id);
const existing = await prisma.collection.findUnique({
where: { id: collectionId },
});
if (!existing || existing.userId !== userId) {
return NextResponse.json({ error: "收藏夹不存在或无权限" }, { status: 403 });
}
await prisma.collection.delete({
where: { id: collectionId },
});
return NextResponse.json({ success: true });
}