69 lines
1.6 KiB
TypeScript
69 lines
1.6 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
import { getServerSession } from 'next-auth'
|
|
import { authOptions } from '@/lib/auth'
|
|
import { prisma } from '@/lib/prisma'
|
|
|
|
// Get single material for sharing (公开访问,无需登录)
|
|
export async function GET(req: NextRequest) {
|
|
try {
|
|
const { searchParams } = new URL(req.url)
|
|
const id = searchParams.get('id')
|
|
|
|
if (!id) {
|
|
return NextResponse.json(
|
|
{ error: '缺少素材ID' },
|
|
{ status: 400 }
|
|
)
|
|
}
|
|
|
|
const material = await prisma.material.findUnique({
|
|
where: { id },
|
|
select: {
|
|
id: true,
|
|
previewUrl: true,
|
|
productModel: true,
|
|
brandName: true,
|
|
seriesName: true,
|
|
skuCode: true,
|
|
materialTexture: true,
|
|
categoryName: true,
|
|
sceneName: true,
|
|
materialType: true,
|
|
renderer: true,
|
|
renderTime: true,
|
|
imageResolution: true,
|
|
colorMode: true,
|
|
authorName: true,
|
|
zipFileName: true,
|
|
zipFileSize: true,
|
|
downloadCount: true,
|
|
likeCount: true,
|
|
displayImages: true,
|
|
createdAt: true
|
|
}
|
|
})
|
|
|
|
if (!material) {
|
|
return NextResponse.json(
|
|
{ error: '素材不存在' },
|
|
{ status: 404 }
|
|
)
|
|
}
|
|
|
|
// 转换BigInt为字符串
|
|
const materialData = {
|
|
...material,
|
|
zipFileSize: material.zipFileSize.toString()
|
|
}
|
|
|
|
return NextResponse.json(materialData)
|
|
} catch (error) {
|
|
console.error('Error fetching material for share:', error)
|
|
return NextResponse.json(
|
|
{ error: '获取素材失败' },
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
}
|
|
|