fix: 增加enhance API的超时时间,解决499错误(客户端关闭连接)
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled

This commit is contained in:
Your Name 2025-12-29 01:29:23 +08:00
parent 2cb7653a71
commit bacac837bd

View File

@ -81,6 +81,9 @@ async function uploadBase64ToS3(base64Data: string, mimeType: string = "image/jp
}
}
// 设置API路由最大执行时间为3分钟(180秒)
export const maxDuration = 180;
/**
* 轮询获取任务结果(根据官方示例)
*/
@ -89,7 +92,7 @@ async function pollTaskResult(
apiKey: string,
taskId: string,
delay: number = 1000,
timeout: number = 30000
timeout: number = 120000 // 增加到120秒(2分钟)
): Promise<any> {
const pollUrl = `${apiUrl}/api/tasks/visual/scale/${taskId}`;
@ -270,9 +273,9 @@ export async function POST(request: NextRequest) {
let taskId: string;
try {
// 添加超时控制(30秒)
// 添加超时控制(60秒)
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 30000);
const timeoutId = setTimeout(() => controller.abort(), 60000);
// 将FormData转换为Buffer(form-data包是stream)
const formDataBuffer = await new Promise<Buffer>((resolve, reject) => {
@ -321,7 +324,7 @@ export async function POST(request: NextRequest) {
return NextResponse.json(
{
error: "变清晰API请求超时",
detail: "请求超过60秒未响应,请检查API服务器状态或网络连接",
detail: "创建任务请求超过60秒未响应,请检查API服务器状态或网络连接",
},
{ status: 504 }
);