45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
import { getServerSession } from 'next-auth'
|
|
import { authOptions } from '@/lib/auth'
|
|
import { prisma } from '@/lib/prisma'
|
|
|
|
// Restore material from trash (admin only)
|
|
export async function POST(req: NextRequest) {
|
|
try {
|
|
const session = await getServerSession(authOptions)
|
|
|
|
if (!session || (session.user as any).role !== 'ADMIN') {
|
|
return NextResponse.json(
|
|
{ error: '无权限' },
|
|
{ status: 403 }
|
|
)
|
|
}
|
|
|
|
// 从请求body中获取id
|
|
const body = await req.json()
|
|
const id = body.id
|
|
|
|
if (!id) {
|
|
return NextResponse.json(
|
|
{ error: '缺少素材ID' },
|
|
{ status: 400 }
|
|
)
|
|
}
|
|
|
|
// Restore material: set deletedAt to null
|
|
await prisma.material.update({
|
|
where: { id },
|
|
data: { deletedAt: null },
|
|
})
|
|
|
|
return NextResponse.json({ message: '恢复成功' })
|
|
} catch (error) {
|
|
console.error('[Materials] RESTORE error:', error)
|
|
return NextResponse.json(
|
|
{ error: '恢复失败' },
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
}
|
|
|