放宽AOS抠图请求超时并延长轮询窗口
This commit is contained in:
parent
49e8731e7f
commit
458b15f889
@ -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 <T,>(
|
||||
fn: (signal: AbortSignal) => Promise<T>,
|
||||
@ -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 : "未知错误" };
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user