devme commited on
Commit
56a6e3f
·
verified ·
1 Parent(s): fac30f2

Delete proxy-manager.js

Browse files
Files changed (1) hide show
  1. proxy-manager.js +0 -37
proxy-manager.js DELETED
@@ -1,37 +0,0 @@
1
- import { HttpsProxyAgent } from 'https-proxy-agent'
2
- import { getProxyUrl } from './config.js'
3
- import { logInfo, logError } from './logger.js'
4
-
5
- let cachedAgent = null
6
- let cachedProxyUrl = null
7
-
8
- export function getNextProxyAgent(targetUrl) {
9
- const proxyUrl = getProxyUrl()
10
-
11
- // 如果没有配置代理,返回 null(直连)
12
- if (!proxyUrl) {
13
- return null
14
- }
15
-
16
- // 如果代理 URL 改变,清除缓存
17
- if (proxyUrl !== cachedProxyUrl) {
18
- cachedAgent = null
19
- cachedProxyUrl = proxyUrl
20
- }
21
-
22
- // 如果已有缓存的代理,直接返回
23
- if (cachedAgent) {
24
- return { agent: cachedAgent, proxy: { url: proxyUrl } }
25
- }
26
-
27
- // 创建新的代理
28
- try {
29
- cachedAgent = new HttpsProxyAgent(proxyUrl)
30
- logInfo(`使用代理 ${proxyUrl} 请求 ${targetUrl}`)
31
- return { agent: cachedAgent, proxy: { url: proxyUrl } }
32
- } catch (error) {
33
- logError(`为 ${proxyUrl} 创建代理失败`, error)
34
- return null
35
- }
36
- }
37
-