chenpei 2b5220fdd7 fix: 任务-详情源文件不再误套 1GB 图片上限
PSD/压缩包按单文件 10GB、合计 30GB 单独限制;提交时续上传会话,避免大文件传完再排队后会话丢失。
2026-08-17 18:48:00 +08:00

72 lines
2.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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) {
console.log(`[RefreshSession] 收到会话刷新请求 at ${new Date().toISOString()}`)
try {
// 验证用户身份
const session = await getServerSession(authOptions)
if (!session) {
console.log(`[RefreshSession] 用户未登录`)
return NextResponse.json({ error: '请先登录' }, { status: 401 })
}
// 解析请求参数
const { uploadId } = await req.json()
if (!uploadId) {
console.log(`[RefreshSession] 缺少uploadId参数`)
return NextResponse.json(
{ error: '缺少uploadId参数' },
{ status: 400 }
)
}
console.log(`[RefreshSession] 尝试刷新会话: ${uploadId}, 用户: ${(session.user as any).id}`)
// 刷新会话TTL
const success = await refreshUploadSession(uploadId)
if (!success) {
console.log(`[RefreshSession] 会话不存在或已过期: ${uploadId}`)
return NextResponse.json(
{ error: '会话不存在或已过期' },
{ status: 404 }
)
}
console.log(`[RefreshSession] 会话刷新成功: ${uploadId}, TTL: 8小时`)
return NextResponse.json({
success: true,
uploadId,
ttl: 8 * 60 * 60 // 8小时(秒)
})
} catch (error) {
console.error('[RefreshSession] 刷新会话失败:', error)
return NextResponse.json(
{ error: '刷新会话失败' },
{ status: 500 }
)
}
}