This commit is contained in:
freedakgmail
2025-11-23 03:07:39 +08:00
parent 626d7dddde
commit e92884ae53
679 changed files with 208175 additions and 1183474 deletions
@@ -0,0 +1,52 @@
import { NextRequest, NextResponse } from "next/server"
import { getServerSession } from "next-auth"
import { authOptions } from "@/lib/auth"
import { prisma } from "@/lib/prisma"
import { checkPermission } from "@/lib/permissions"
// 获取家族树的活动日志
export async function GET(
req: NextRequest,
{ params }: { params: Promise<{ treeId: string }> }
) {
try {
const session = await getServerSession(authOptions)
if (!session?.user?.id) {
return NextResponse.json({ error: "未授权" }, { status: 401 })
}
const { treeId } = await params
const { searchParams } = new URL(req.url)
const limit = parseInt(searchParams.get('limit') || '50')
// 检查权限
const { hasPermission } = await checkPermission(session.user.id, treeId)
if (!hasPermission) {
return NextResponse.json({ error: "无权访问此家族树" }, { status: 403 })
}
const logs = await prisma.activityLog.findMany({
where: { treeId },
orderBy: { timestamp: 'desc' },
take: limit,
include: {
user: {
select: {
id: true,
name: true,
email: true,
}
}
}
})
return NextResponse.json({ logs })
} catch (error) {
console.error("获取活动日志失败:", error)
return NextResponse.json(
{ error: "获取活动日志失败" },
{ status: 500 }
)
}
}