fix bug
This commit is contained in:
+12
-9
@@ -806,7 +806,7 @@ class YouProvider {
|
|||||||
}]));
|
}]));
|
||||||
req_param.append("chat", JSON.stringify(userMessage));
|
req_param.append("chat", JSON.stringify(userMessage));
|
||||||
const url = "https://you.com/api/streamingSearch?" + req_param.toString();
|
const url = "https://you.com/api/streamingSearch?" + req_param.toString();
|
||||||
await page.goto(`https://you.com/search?q=&fromSearchBar=true&tbm=youchat&chatMode=custom`, { waitUntil: "domcontentloaded" });
|
await page.goto(`https://you.com/search?q=&fromSearchBar=true&tbm=youchat&chatMode=custom`, {waitUntil: "domcontentloaded"});
|
||||||
|
|
||||||
async function establishConnection(session, page, emitter, traceId) {
|
async function establishConnection(session, page, emitter, traceId) {
|
||||||
try {
|
try {
|
||||||
@@ -816,7 +816,7 @@ class YouProvider {
|
|||||||
console.log(`[${60 - i}]秒后开始发送请求`);
|
console.log(`[${60 - i}]秒后开始发送请求`);
|
||||||
}
|
}
|
||||||
|
|
||||||
await page.goto(`https://you.com/search?q=&fromSearchBar=true&tbm=youchat&chatMode=custom`, { waitUntil: "domcontentloaded" });
|
await page.goto(`https://you.com/search?q=&fromSearchBar=true&tbm=youchat&chatMode=custom`, {waitUntil: "domcontentloaded"});
|
||||||
|
|
||||||
const connectionEstablished = await delayedRequestWithRetry();
|
const connectionEstablished = await delayedRequestWithRetry();
|
||||||
if (!connectionEstablished) {
|
if (!connectionEstablished) {
|
||||||
@@ -847,7 +847,7 @@ class YouProvider {
|
|||||||
clearTimeout(timeoutId);
|
clearTimeout(timeoutId);
|
||||||
// 读取响应的前几个字节,确保连接已经建立
|
// 读取响应的前几个字节,确保连接已经建立
|
||||||
const reader = res.body.getReader();
|
const reader = res.body.getReader();
|
||||||
const { done } = await reader.read();
|
const {done} = await reader.read();
|
||||||
if (!done) {
|
if (!done) {
|
||||||
await reader.cancel();
|
await reader.cancel();
|
||||||
}
|
}
|
||||||
@@ -866,12 +866,12 @@ class YouProvider {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
if (response.status === 403 && response.headers['cf-chl-bypass']) {
|
if (response.status === 403 && response.headers['cf-chl-bypass']) {
|
||||||
return { connected: false, cloudflareDetected: true };
|
return {connected: false, cloudflareDetected: true};
|
||||||
}
|
}
|
||||||
return { connected: true, cloudflareDetected: false };
|
return {connected: true, cloudflareDetected: false};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Connection check error:", error);
|
console.error("Connection check error:", error);
|
||||||
return { connected: false, cloudflareDetected: false, error: error.message };
|
return {connected: false, cloudflareDetected: false, error: error.message};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -888,7 +888,7 @@ class YouProvider {
|
|||||||
await new Promise(resolve => setTimeout(resolve, 4000)); // 4秒延迟
|
await new Promise(resolve => setTimeout(resolve, 4000)); // 4秒延迟
|
||||||
console.log(`尝试发送请求 (尝试 ${attempt}/${maxRetries})`);
|
console.log(`尝试发送请求 (尝试 ${attempt}/${maxRetries})`);
|
||||||
|
|
||||||
const { connected, cloudflareDetected, error } = await checkConnectionAndCloudflare(page);
|
const {connected, cloudflareDetected, error} = await checkConnectionAndCloudflare(page);
|
||||||
|
|
||||||
if (connected) {
|
if (connected) {
|
||||||
console.log("连接成功,准备唤醒浏览器");
|
console.log("连接成功,准备唤醒浏览器");
|
||||||
@@ -1004,9 +1004,12 @@ class YouProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const connectionEstablished = await establishConnection(session, page, emitter, traceId);
|
const connectionEstablished = await delayedRequestWithRetry();
|
||||||
if (!connectionEstablished) {
|
if (!connectionEstablished) {
|
||||||
return { completion: emitter, cancel: () => {} };
|
return {
|
||||||
|
completion: emitter, cancel: () => {
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
responseTimeout = setTimeout(async () => {
|
responseTimeout = setTimeout(async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user