From 458b15f8895dc66fe657c8671362c2068fe85963 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 15 Feb 2026 23:13:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=BE=E5=AE=BDAOS=E6=8A=A0=E5=9B=BE?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E8=B6=85=E6=97=B6=E5=B9=B6=E5=BB=B6=E9=95=BF?= =?UTF-8?q?=E8=BD=AE=E8=AF=A2=E7=AA=97=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/rmbg/route.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/api/rmbg/route.ts b/app/api/rmbg/route.ts index 42ffe549c..918a8dc49 100644 --- a/app/api/rmbg/route.ts +++ b/app/api/rmbg/route.ts @@ -89,6 +89,9 @@ async function uploadBase64ToS3(base64Data: string, mimeType: string = "image/pn } const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); +const AOS_CREATE_TIMEOUT_MS = 120_000; +const AOS_POLL_TIMEOUT_MS = 60_000; +const AOS_DOWNLOAD_TIMEOUT_MS = 60_000; const withTimeout = async ( fn: (signal: AbortSignal) => Promise, @@ -263,6 +266,7 @@ async function processWithAosSegmentation( createForm.append("type", config.foregroundType); } + console.log("[AOS RMBG] creating segmentation task..."); const createResponse = await withTimeout( (signal) => fetch(createUrl, { @@ -271,7 +275,7 @@ async function processWithAosSegmentation( body: createForm, signal, }), - 30000 + AOS_CREATE_TIMEOUT_MS ); const createPayload = await createResponse.json().catch(() => null); @@ -284,7 +288,7 @@ async function processWithAosSegmentation( const taskId = createPayload.data.task_id as string; const taskUrl = `${createUrl}/${taskId}`; - const maxPollCount = 30; + const maxPollCount = 60; for (let pollCount = 0; pollCount < maxPollCount; pollCount++) { await sleep(1000); @@ -296,7 +300,7 @@ async function processWithAosSegmentation( headers, signal, }), - 30000 + AOS_POLL_TIMEOUT_MS ); const pollPayload = await pollResponse.json().catch(() => null); @@ -323,7 +327,7 @@ async function processWithAosSegmentation( method: "GET", signal, }), - 30000 + AOS_DOWNLOAD_TIMEOUT_MS ); if (!imageResponse.ok) { @@ -350,10 +354,10 @@ async function processWithAosSegmentation( } } - return { success: false, error: "AOS任务超时(30秒)" }; + return { success: false, error: "AOS任务超时(最多60秒)" }; } catch (error) { if (error instanceof Error && error.name === "AbortError") { - return { success: false, error: "AOS请求超时(30秒)" }; + return { success: false, error: "AOS请求超时,请稍后重试" }; } return { success: false, error: error instanceof Error ? error.message : "未知错误" }; }