import { NextRequest, NextResponse } from 'next/server' import { getServerSession } from 'next-auth' import { authOptions } from '@/lib/auth' import { refreshUploadSession } from '@/lib/upload-sessions' // Configure route export const runtime = 'nodejs' export const dynamic = 'force-dynamic' /** * 刷新上传会话API * 用于会话过期后恢复上传,不清空已上传的分片记录 * * POST /api/materials/upload/refresh * Body: { uploadId: string } * * 返回: * - success: true/false * - uploadId: string * - ttl: number (秒) */ export async function POST(req: NextRequest) { try { // 验证用户身份 const session = await getServerSession(authOptions) if (!session) { return NextResponse.json({ error: '请先登录' }, { status: 401 }) } // 解析请求参数 const { uploadId } = await req.json() if (!uploadId) { return NextResponse.json( { error: '缺少uploadId参数' }, { status: 400 } ) } // 刷新会话TTL const success = await refreshUploadSession(uploadId) if (!success) { return NextResponse.json( { error: '会话不存在或已过期' }, { status: 404 } ) } return NextResponse.json({ success: true, uploadId, ttl: 8 * 60 * 60 // 8小时(秒) }) } catch (error) { console.error('[RefreshSession] 刷新会话失败:', error) return NextResponse.json( { error: '刷新会话失败' }, { status: 500 } ) } }