import { NextRequest, NextResponse } from 'next/server' import { getServerSession } from 'next-auth' import { authOptions } from '@/lib/auth' import { getLatestTaskDetailUploadJobStatus, getTaskDetailUploadJobStatus, } from '@/lib/task-detail-upload-jobs' export const runtime = 'nodejs' export const dynamic = 'force-dynamic' export const maxDuration = 30 export async function GET(request: NextRequest) { try { const session = await getServerSession(authOptions) const operatorUserId = (session?.user as { id?: string } | undefined)?.id if (!operatorUserId) { return NextResponse.json({ success: false, error: '未登录' }, { status: 401 }) } const jobId = request.nextUrl.searchParams.get('jobId')?.trim() || '' const materialId = request.nextUrl.searchParams.get('materialId')?.trim() || '' if ((!jobId && !materialId) || jobId.length > 100 || materialId.length > 100) { return NextResponse.json({ success: false, error: '缺少有效的 jobId 或 materialId' }, { status: 400 }) } const job = jobId ? await getTaskDetailUploadJobStatus(jobId, operatorUserId) : await getLatestTaskDetailUploadJobStatus(materialId, operatorUserId) if (!job) { // 不区分“任务不存在”和“任务属于其他用户”,避免泄露任务状态。 return NextResponse.json({ success: false, error: '任务不存在或无权限查看' }, { status: 404 }) } return NextResponse.json({ success: true, data: job }) } catch (error) { console.error('[Product Package Status] Error:', error) return NextResponse.json( { success: false, error: error instanceof Error ? error.message : '服务器错误' }, { status: 500 }, ) } }