add delayed sending switch
This commit is contained in:
+18
-2
@@ -806,17 +806,23 @@ class YouProvider {
|
||||
}]));
|
||||
req_param.append("chat", JSON.stringify(userMessage));
|
||||
const url = "https://you.com/api/streamingSearch?" + req_param.toString();
|
||||
const enableDelayLogic = process.env.ENABLE_DELAY_LOGIC === 'true'; // 是否启用延迟逻辑
|
||||
|
||||
if (enableDelayLogic) {
|
||||
await page.goto(`https://you.com/search?q=&fromSearchBar=true&tbm=youchat&chatMode=custom`, {waitUntil: "domcontentloaded"});
|
||||
}
|
||||
|
||||
|
||||
async function establishConnection(session, page, emitter, traceId) {
|
||||
try {
|
||||
await session.page.goto("https://you.com", {waitUntil: 'domcontentloaded'});
|
||||
for (let i = 0; i < 60; i++) {
|
||||
for (let i = 0; i < 40; i++) {
|
||||
await sleep(1000);
|
||||
console.log(`[${60 - i}]秒后开始发送请求`);
|
||||
console.log(`[${40 - i}]秒后开始发送请求`);
|
||||
}
|
||||
|
||||
await page.goto(`https://you.com/search?q=&fromSearchBar=true&tbm=youchat&chatMode=custom`, {waitUntil: "domcontentloaded"});
|
||||
await sleep(4000);
|
||||
|
||||
const connectionEstablished = await delayedRequestWithRetry();
|
||||
if (!connectionEstablished) {
|
||||
@@ -885,6 +891,7 @@ class YouProvider {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (enableDelayLogic) {
|
||||
await new Promise(resolve => setTimeout(resolve, 4000)); // 4秒延迟
|
||||
console.log(`尝试发送请求 (尝试 ${attempt}/${maxRetries})`);
|
||||
|
||||
@@ -920,6 +927,11 @@ class YouProvider {
|
||||
} else {
|
||||
console.log(`连接失败,准备重试 (${attempt}/${maxRetries}). 错误: ${error || 'Unknown'}`);
|
||||
}
|
||||
} else {
|
||||
console.log("开始发送请求");
|
||||
emitter.emit("start", traceId);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
console.error("达到最大重试次数,连接失败");
|
||||
emitter.emit("error", new Error("Failed to establish connection after maximum retries"));
|
||||
@@ -1012,6 +1024,10 @@ class YouProvider {
|
||||
};
|
||||
}
|
||||
|
||||
if (!enableDelayLogic) {
|
||||
await page.goto(`https://you.com/search?q=&fromSearchBar=true&tbm=youchat&chatMode=custom`, {waitUntil: "domcontentloaded"});
|
||||
}
|
||||
|
||||
responseTimeout = setTimeout(async () => {
|
||||
if (!responseStarted) {
|
||||
console.log("40秒内没有收到响应,重新建立连接");
|
||||
|
||||
Reference in New Issue
Block a user