clash-linux commited on
Commit
e6f2a4a
·
verified ·
1 Parent(s): 67d77c8

Upload 15 files

Browse files
src/CookieManager.js CHANGED
@@ -253,13 +253,6 @@ class CookieManager {
253
  body: JSON.stringify({}),
254
  };
255
 
256
- // 添加代理配置(如果有)
257
- if (this.proxyUrl) {
258
- const { HttpsProxyAgent } = await import('https-proxy-agent');
259
- fetchOptions.agent = new HttpsProxyAgent(this.proxyUrl);
260
- logger.info(`使用代理: ${this.proxyUrl}`);
261
- }
262
-
263
  // 发送请求
264
  const response = await fetch("https://www.notion.so/api/v3/getSpaces", fetchOptions);
265
 
 
253
  body: JSON.stringify({}),
254
  };
255
 
 
 
 
 
 
 
 
256
  // 发送请求
257
  const response = await fetch("https://www.notion.so/api/v3/getSpaces", fetchOptions);
258
 
src/ProxyPool.js CHANGED
@@ -9,15 +9,15 @@ class ProxyPool {
9
  * @param {Object} options - 配置选项
10
  * @param {number} options.targetCount - 目标代理数量,默认20
11
  * @param {number} options.batchSize - 每次获取的代理数量,默认20
12
- * @param {number} options.testTimeout - 测试代理超时时间(毫秒),默认5000
13
- * @param {number} options.requestTimeout - 请求目标网站超时时间(毫秒),默认10000
14
  * @param {string} options.targetUrl - 目标网站URL,默认'https://www.notion.so'
15
- * @param {number} options.concurrentRequests - 并发请求数量,默认10
16
  * @param {number} options.minThreshold - 可用代理数量低于此阈值时自动补充,默认5
17
  * @param {number} options.checkInterval - 检查代理池状态的时间间隔(毫秒),默认30000
18
  * @param {string} options.proxyProtocol - 代理协议,默认'http'
19
- * @param {number} options.maxRefillAttempts - 最大补充尝试次数,默认20
20
- * @param {number} options.retryDelay - 重试延迟(毫秒),默认1000
21
  * @param {boolean} options.useCache - 是否使用缓存,默认true
22
  * @param {number} options.cacheExpiry - 缓存过期时间(毫秒),默认3600000 (1小时)
23
  * @param {string} options.logLevel - 日志级别,可选值:'debug', 'info', 'warn', 'error', 'none',默认'info'
@@ -27,15 +27,15 @@ class ProxyPool {
27
  // 配置参数
28
  this.targetCount = options.targetCount || 20;
29
  this.batchSize = options.batchSize || 20;
30
- this.testTimeout = options.testTimeout || 5000;
31
- this.requestTimeout = options.requestTimeout || 10000;
32
  this.targetUrl = options.targetUrl || 'https://www.notion.so';
33
- this.concurrentRequests = options.concurrentRequests || 10;
34
  this.minThreshold = options.minThreshold || 5;
35
  this.checkInterval = options.checkInterval || 30000; // 默认30秒检查一次
36
  this.proxyProtocol = options.proxyProtocol || 'http';
37
- this.maxRefillAttempts = options.maxRefillAttempts || 20; // 减少最大尝试次数
38
- this.retryDelay = options.retryDelay || 1000; // 减少重试延迟
39
  this.useCache = options.useCache !== undefined ? options.useCache : true;
40
  this.cacheExpiry = options.cacheExpiry || 3600000; // 默认1小时
41
  this.logLevel = options.logLevel || 'info'; // 默认日志级别为info
@@ -237,7 +237,7 @@ class ProxyPool {
237
 
238
  // 计算本次需要获取的批次大小
239
  const remainingNeeded = this.targetCount - this.availableProxies.length;
240
- const batchSizeNeeded = Math.max(this.batchSize, remainingNeeded * 2); // 获取更多代理以提高成功率
241
 
242
  // 获取代理
243
  const proxies = await this.getProxiesFromProvider(batchSizeNeeded);
@@ -253,6 +253,7 @@ class ProxyPool {
253
 
254
  if (newProxies.length === 0) {
255
  this.log('debug', '所有获取的代理都已存在,继续获取新代理...');
 
256
  continue;
257
  }
258
 
@@ -274,9 +275,9 @@ class ProxyPool {
274
  break;
275
  }
276
 
277
- // 如果还没补充到足够的代理,等待一段时间再继续
278
  if (this.availableProxies.length < this.targetCount) {
279
- await new Promise(resolve => setTimeout(resolve, this.retryDelay));
280
  }
281
  }
282
  } catch (error) {
@@ -426,43 +427,85 @@ class ProxyPool {
426
  async getProxiesFromProvider(count = null) {
427
  try {
428
  const requestCount = count || this.batchSize;
429
- // 限制请求数量最大为10
430
  const actualCount = Math.min(requestCount, 10);
431
- const url = `https://proxy.doudouzi.me/random/${this.proxyCountry}?number=${actualCount}&protocol=${this.proxyProtocol}&type=json`;
432
- this.log('debug', `正在获取代理,URL: ${url}`);
433
 
434
- const response = await axios.get(url, {
435
- timeout: 10000,
436
- validateStatus: status => true
437
- });
 
 
438
 
439
- if (response.data) {
440
- // 解析返回的数据格式
441
- const proxyDataArray = response.data.trim().split('\n').filter(line => line.trim() !== '');
442
- const proxies = [];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
443
 
444
- for (const line of proxyDataArray) {
445
- try {
446
- const proxyData = JSON.parse(line);
447
- if (proxyData.ip && proxyData.port) {
448
- // 如果有用户名和密码,则使用认证格式
449
- if (proxyData.username && proxyData.password) {
450
- proxies.push(`${proxyData.ip}:${proxyData.port}:${proxyData.username}:${proxyData.password}`);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
451
  } else {
452
- proxies.push(`${proxyData.ip}:${proxyData.port}`);
453
  }
454
  }
455
- } catch (err) {
456
- this.log('error', '解析代理数据出错:', err.message);
457
  }
458
  }
459
-
460
- this.log('debug', `成功获取 ${proxies.length} 个代理`);
461
- return proxies;
462
- } else {
463
- this.log('error', '获取代理失败: 返回数据格式不正确');
464
- return [];
465
  }
 
 
 
466
  } catch (error) {
467
  this.log('error', '获取代理出错:', error.message);
468
  return [];
@@ -479,7 +522,7 @@ class ProxyPool {
479
  const remainingNeeded = this.targetCount - this.availableProxies.length;
480
 
481
  // 增加并发数以加快处理速度
482
- const concurrentRequests = Math.min(this.concurrentRequests * 2, 20);
483
 
484
  // 分批处理代理
485
  for (let i = 0; i < proxies.length; i += concurrentRequests) {
@@ -559,9 +602,9 @@ class ProxyPool {
559
  'Connection': 'keep-alive',
560
  'Upgrade-Insecure-Requests': '1'
561
  },
562
- timeout: this.requestTimeout,
563
  validateStatus: status => true,
564
- maxRedirects: 10,
565
  followRedirect: true
566
  });
567
 
@@ -695,10 +738,12 @@ async function example() {
695
  minThreshold: 3, // 当可用代理少于3个时,自动补充
696
  checkInterval: 60000, // 每60秒检查一次
697
  targetUrl: 'https://www.notion.so',
698
- concurrentRequests: 15, // 增加并发请求数
699
  useCache: true, // 启用缓存
700
- maxRefillAttempts: 15, // 减少最大尝试次数
701
- retryDelay: 1000, // 减少重试延迟
 
 
702
  logLevel: 'info', // 设置日志级别
703
  showProgressBar: true // 启用进度条
704
  });
 
9
  * @param {Object} options - 配置选项
10
  * @param {number} options.targetCount - 目标代理数量,默认20
11
  * @param {number} options.batchSize - 每次获取的代理数量,默认20
12
+ * @param {number} options.testTimeout - 测试代理超时时间(毫秒),默认3000
13
+ * @param {number} options.requestTimeout - 请求目标网站超时时间(毫秒),默认5000
14
  * @param {string} options.targetUrl - 目标网站URL,默认'https://www.notion.so'
15
+ * @param {number} options.concurrentRequests - 并发请求数量,默认15
16
  * @param {number} options.minThreshold - 可用代理数量低于此阈值时自动补充,默认5
17
  * @param {number} options.checkInterval - 检查代理池状态的时间间隔(毫秒),默认30000
18
  * @param {string} options.proxyProtocol - 代理协议,默认'http'
19
+ * @param {number} options.maxRefillAttempts - 最大补充尝试次数,默认50
20
+ * @param {number} options.retryDelay - 重试延迟(毫秒),默认500
21
  * @param {boolean} options.useCache - 是否使用缓存,默认true
22
  * @param {number} options.cacheExpiry - 缓存过期时间(毫秒),默认3600000 (1小时)
23
  * @param {string} options.logLevel - 日志级别,可选值:'debug', 'info', 'warn', 'error', 'none',默认'info'
 
27
  // 配置参数
28
  this.targetCount = options.targetCount || 20;
29
  this.batchSize = options.batchSize || 20;
30
+ this.testTimeout = options.testTimeout || 3000; // 减少测试超时时间
31
+ this.requestTimeout = options.requestTimeout || 5000; // 减少请求超时时间
32
  this.targetUrl = options.targetUrl || 'https://www.notion.so';
33
+ this.concurrentRequests = options.concurrentRequests || 15; // 增加默认并发请求数
34
  this.minThreshold = options.minThreshold || 5;
35
  this.checkInterval = options.checkInterval || 30000; // 默认30秒检查一次
36
  this.proxyProtocol = options.proxyProtocol || 'http';
37
+ this.maxRefillAttempts = options.maxRefillAttempts || 50; // 增加最大尝试次数
38
+ this.retryDelay = options.retryDelay || 500; // 减少重试延迟
39
  this.useCache = options.useCache !== undefined ? options.useCache : true;
40
  this.cacheExpiry = options.cacheExpiry || 3600000; // 默认1小时
41
  this.logLevel = options.logLevel || 'info'; // 默认日志级别为info
 
237
 
238
  // 计算本次需要获取的批次大小
239
  const remainingNeeded = this.targetCount - this.availableProxies.length;
240
+ const batchSizeNeeded = Math.max(remainingNeeded * 2, 10); // 获取更多代理以提高成功率,至少10个
241
 
242
  // 获取代理
243
  const proxies = await this.getProxiesFromProvider(batchSizeNeeded);
 
253
 
254
  if (newProxies.length === 0) {
255
  this.log('debug', '所有获取的代理都已存在,继续获取新代理...');
256
+ // 减少等待时间,立即继续尝试
257
  continue;
258
  }
259
 
 
275
  break;
276
  }
277
 
278
+ // 如果还没补充到足够的代理,减少等待时间再继续
279
  if (this.availableProxies.length < this.targetCount) {
280
+ await new Promise(resolve => setTimeout(resolve, 500)); // 减少等待时间到500毫秒
281
  }
282
  }
283
  } catch (error) {
 
427
  async getProxiesFromProvider(count = null) {
428
  try {
429
  const requestCount = count || this.batchSize;
430
+ // 限制单次请求数量最大为10
431
  const actualCount = Math.min(requestCount, 10);
 
 
432
 
433
+ // 计算需要发送的请求数量,以获取足够的代理
434
+ const requestsNeeded = Math.ceil(requestCount / 1); // 假设每次请求只返回1个代理
435
+ const maxParallelRequests = 5; // 最大并行请求数
436
+ const actualRequests = Math.min(requestsNeeded, maxParallelRequests);
437
+
438
+ this.log('debug', `需要 ${requestCount} 个代理,将发送 ${actualRequests} 个并行请求`);
439
 
440
+ // 并行发送多个请求
441
+ const requestPromises = [];
442
+ for (let i = 0; i < actualRequests; i++) {
443
+ const url = `https://proxy.doudouzi.me/random/${this.proxyCountry}?number=${actualCount}&protocol=${this.proxyProtocol}&type=json`;
444
+ requestPromises.push(
445
+ axios.get(url, {
446
+ timeout: 10000,
447
+ validateStatus: status => true
448
+ })
449
+ );
450
+ }
451
+
452
+ // 等待所有请求完成
453
+ const responses = await Promise.all(requestPromises);
454
+
455
+ // 处理所有响应,合并代理列表
456
+ let proxies = [];
457
+
458
+ for (const response of responses) {
459
+ if (!response.data) continue;
460
 
461
+ // 处理不同的返回格式
462
+ if (typeof response.data === 'string') {
463
+ // 如果返回的是字符串,尝试按行解析
464
+ const proxyDataArray = response.data.trim().split('\n').filter(line => line.trim() !== '');
465
+
466
+ for (const line of proxyDataArray) {
467
+ try {
468
+ const proxyData = JSON.parse(line);
469
+ if (proxyData.ip && proxyData.port) {
470
+ // 如果有用户名和密码,则使用认证格式
471
+ if (proxyData.username && proxyData.password) {
472
+ proxies.push(`${proxyData.ip}:${proxyData.port}:${proxyData.username}:${proxyData.password}`);
473
+ } else {
474
+ proxies.push(`${proxyData.ip}:${proxyData.port}`);
475
+ }
476
+ }
477
+ } catch (err) {
478
+ this.log('error', '解析代理数据出错:', err.message);
479
+ }
480
+ }
481
+ } else if (typeof response.data === 'object') {
482
+ // 如果返回的是对象
483
+ if (Array.isArray(response.data)) {
484
+ // 如果是数组,遍历处理
485
+ for (const proxyData of response.data) {
486
+ if (proxyData.ip && proxyData.port) {
487
+ if (proxyData.username && proxyData.password) {
488
+ proxies.push(`${proxyData.ip}:${proxyData.port}:${proxyData.username}:${proxyData.password}`);
489
+ } else {
490
+ proxies.push(`${proxyData.ip}:${proxyData.port}`);
491
+ }
492
+ }
493
+ }
494
+ } else {
495
+ // 如果是单个对象
496
+ if (response.data.ip && response.data.port) {
497
+ if (response.data.username && response.data.password) {
498
+ proxies.push(`${response.data.ip}:${response.data.port}:${response.data.username}:${response.data.password}`);
499
  } else {
500
+ proxies.push(`${response.data.ip}:${response.data.port}`);
501
  }
502
  }
 
 
503
  }
504
  }
 
 
 
 
 
 
505
  }
506
+
507
+ this.log('debug', `成功获取 ${proxies.length} 个代理`);
508
+ return proxies;
509
  } catch (error) {
510
  this.log('error', '获取代理出错:', error.message);
511
  return [];
 
522
  const remainingNeeded = this.targetCount - this.availableProxies.length;
523
 
524
  // 增加并发数以加快处理速度
525
+ const concurrentRequests = Math.min(this.concurrentRequests * 3, 30); // 增加到最多30个并发请求
526
 
527
  // 分批处理代理
528
  for (let i = 0; i < proxies.length; i += concurrentRequests) {
 
602
  'Connection': 'keep-alive',
603
  'Upgrade-Insecure-Requests': '1'
604
  },
605
+ timeout: Math.min(this.requestTimeout, 5000), // 减少超时时间,最多5秒
606
  validateStatus: status => true,
607
+ maxRedirects: 5, // 减少最大重定向次数
608
  followRedirect: true
609
  });
610
 
 
738
  minThreshold: 3, // 当可用代理少于3个时,自动补充
739
  checkInterval: 60000, // 每60秒检查一次
740
  targetUrl: 'https://www.notion.so',
741
+ concurrentRequests: 20, // 增加并发请求数
742
  useCache: true, // 启用缓存
743
+ maxRefillAttempts: 50, // 增加最大尝试次数
744
+ retryDelay: 500, // 减少重试延迟
745
+ testTimeout: 3000, // 减少测试超时时间
746
+ requestTimeout: 5000, // 减少请求超时时间
747
  logLevel: 'info', // 设置日志级别
748
  showProgressBar: true // 启用进度条
749
  });
src/ProxyServer.js CHANGED
@@ -26,13 +26,7 @@ class ProxyServer {
26
  this.proxyProcess = null;
27
  this.platform = process.env.PROXY_SERVER_PLATFORM || 'auto';
28
  this.port = process.env.PROXY_SERVER_PORT || 10655;
29
-
30
- // 检查是否在Linux环境下,并且没有指定日志路径
31
- const defaultLogPath = os.platform() === 'linux' && !process.env.PROXY_SERVER_LOG_PATH
32
- ? '/tmp/proxy_server.log'
33
- : './proxy_server.log';
34
-
35
- this.logPath = process.env.PROXY_SERVER_LOG_PATH || defaultLogPath;
36
  this.enabled = process.env.ENABLE_PROXY_SERVER === 'true';
37
  this.proxyAuthToken = process.env.PROXY_AUTH_TOKEN || 'default_token';
38
  this.logStream = null;
@@ -103,11 +97,9 @@ class ProxyServer {
103
  // 确保可执行文件有执行权限(在Linux/Android上)
104
  if (this.detectPlatform() !== 'windows') {
105
  try {
106
- // 在Docker等只读文件系统中,这可能会失败,但我们在Dockerfile中已经设置了权限
107
- // fs.chmodSync(proxyServerPath, 0o755);
108
  } catch (err) {
109
- // 忽略这个错误,因为可能是在一个只读的环境中
110
- // logger.warning(`无法设置执行权限: ${err.message}`);
111
  }
112
  }
113
 
 
26
  this.proxyProcess = null;
27
  this.platform = process.env.PROXY_SERVER_PLATFORM || 'auto';
28
  this.port = process.env.PROXY_SERVER_PORT || 10655;
29
+ this.logPath = process.env.PROXY_SERVER_LOG_PATH || './proxy_server.log';
 
 
 
 
 
 
30
  this.enabled = process.env.ENABLE_PROXY_SERVER === 'true';
31
  this.proxyAuthToken = process.env.PROXY_AUTH_TOKEN || 'default_token';
32
  this.logStream = null;
 
97
  // 确保可执行文件有执行权限(在Linux/Android上)
98
  if (this.detectPlatform() !== 'windows') {
99
  try {
100
+ fs.chmodSync(proxyServerPath, 0o755);
 
101
  } catch (err) {
102
+ logger.warning(`无法设置执行权限: ${err.message}`);
 
103
  }
104
  }
105
 
src/lightweight-client-express.js CHANGED
@@ -321,7 +321,7 @@ app.get('/cookies/status', authenticate, (req, res) => {
321
  const PORT = process.env.PORT || 7860;
322
 
323
  // 设置代理池日志级别为warn,减少详细日志输出
324
- proxyPool.logLevel = 'error';
325
 
326
  // 初始化并启动服务器
327
  initialize().then(() => {
 
321
  const PORT = process.env.PORT || 7860;
322
 
323
  // 设置代理池日志级别为warn,减少详细日志输出
324
+ proxyPool.logLevel = 'info';
325
 
326
  // 初始化并启动服务器
327
  initialize().then(() => {
src/lightweight-client.js CHANGED
@@ -403,7 +403,7 @@ async function fetchNotionResponse(chunkQueue, notionRequestBody, headers, notio
403
  proxy = proxyPool.getProxy();
404
  fetchOptions.agent = new HttpsProxyAgent(proxy.full);
405
  logger.info(`使用代理: ${proxy.full}`);
406
- }else if(!ENABLE_PROXY_SERVER && PROXY_URL){
407
  const { HttpsProxyAgent } = await import('https-proxy-agent');
408
  fetchOptions.agent = new HttpsProxyAgent(PROXY_URL);
409
  logger.info(`使用代理: ${PROXY_URL}`);
@@ -855,7 +855,7 @@ async function initialize() {
855
  if (process.env.USE_NATIVE_PROXY_POOL === 'true') {
856
  logger.info(`正在初始化本地代理池...`);
857
  // 设置代理池的日志级别为warn,减少详细日志输出
858
- proxyPool.logLevel = 'error';
859
  // 启用进度条显示
860
  proxyPool.showProgressBar = true;
861
 
 
403
  proxy = proxyPool.getProxy();
404
  fetchOptions.agent = new HttpsProxyAgent(proxy.full);
405
  logger.info(`使用代理: ${proxy.full}`);
406
+ }else if(PROXY_URL){
407
  const { HttpsProxyAgent } = await import('https-proxy-agent');
408
  fetchOptions.agent = new HttpsProxyAgent(PROXY_URL);
409
  logger.info(`使用代理: ${PROXY_URL}`);
 
855
  if (process.env.USE_NATIVE_PROXY_POOL === 'true') {
856
  logger.info(`正在初始化本地代理池...`);
857
  // 设置代理池的日志级别为warn,减少详细日志输出
858
+ proxyPool.logLevel = 'info';
859
  // 启用进度条显示
860
  proxyPool.showProgressBar = true;
861
 
src/proxy/chrome_proxy_server_android_arm64 CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:e4fce54fee0fe3acc4d255517134dcabb9dc3086e9dbe571bc9f8f216ba64039
3
- size 12863727
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9112e4db1662224d93d2d24a30757333772f7338f059b926b1c3a9259679ab8f
3
+ size 12876212
src/proxy/chrome_proxy_server_linux_amd64 CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:2e33e31ff51fb711daff95ca41f84e5f56dbfc9c57b90df3761bc1d69e57bfa9
3
- size 12845606
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1821473bb2f1ef3b6e49b5ada7f53489055febf5510cef14593ae74a0e0ea32c
3
+ size 12856741
src/proxy/chrome_proxy_server_windows_amd64.exe CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:bb09f4ed7261e2f0db9be7b1c37df628549df6243aee4c6e3b25d3e9452028f6
3
- size 12961280
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0f4e3b606b6b9bf118b8de79e80778eda24c2b9511e562cc9f5813d803bd69f7
3
+ size 12977664