proxy-pool-manager 1.0.10 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -12
- package/dist/Request.d.ts +4 -0
- package/dist/Request.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/proxyManager.d.ts +6 -1
- package/dist/proxyManager.d.ts.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
## ✨ 特性
|
|
6
6
|
|
|
7
7
|
- 🪶 **内存代理**:代理列表由 `proxies` 传入,只保存在进程内存中
|
|
8
|
-
- 🔄
|
|
8
|
+
- 🔄 **可选轮换**:`rotateOnError: true` 时,上游代理失败才换下一条;默认关闭,重试沿用本次代理
|
|
9
9
|
- 🌐 **HTTP 请求封装**:内置 HTTP 客户端,支持自动代理切换或直接指定代理
|
|
10
10
|
- 📊 **代理健康检查**:自动检测代理可用性,支持自定义检测规则(可选)
|
|
11
11
|
- 🎯 **多种代理策略**:支持顺序、随机、故障转移三种策略
|
|
@@ -48,7 +48,9 @@ const responseWithProxy = await sdk.post('http://your-api.com/request', {
|
|
|
48
48
|
console.log(response.data);
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
-
###
|
|
51
|
+
### 传入代理数组
|
|
52
|
+
|
|
53
|
+
失败后换下一条需要 `rotateOnError: true`,默认关闭。
|
|
52
54
|
|
|
53
55
|
代理只存在当前进程内存中,进程退出后清空。
|
|
54
56
|
|
|
@@ -142,6 +144,7 @@ interface SDKOptions {
|
|
|
142
144
|
retryDelay?: number; // 重试间隔(毫秒),默认使用指数退避策略
|
|
143
145
|
retryDelayBase?: number; // 指数退避的基础延迟(毫秒),默认 1000
|
|
144
146
|
retryDelayMultiplier?: number; // 指数退避的倍数,默认 2
|
|
147
|
+
rotateOnError?: boolean; // 上游代理失败时换下一条,默认 false
|
|
145
148
|
proxyCheckEnabled?: boolean; // 是否启用代理检查,默认 true
|
|
146
149
|
proxyCheckOptions?: { // 代理检查配置(启用健康检查时需要)
|
|
147
150
|
mainUrl: string; // 代理检查主 URL(启用代理检查时必需)
|
|
@@ -525,7 +528,7 @@ const response = await sdk.post('http://your-api.com/request', {
|
|
|
525
528
|
});
|
|
526
529
|
```
|
|
527
530
|
|
|
528
|
-
#### 3.
|
|
531
|
+
#### 3. 使用代理数组
|
|
529
532
|
|
|
530
533
|
```typescript
|
|
531
534
|
// 创建 SDK 时传入代理数组
|
|
@@ -539,8 +542,8 @@ const sdk = await createProxyRequest({
|
|
|
539
542
|
maxRetries: 3
|
|
540
543
|
});
|
|
541
544
|
|
|
542
|
-
//
|
|
543
|
-
//
|
|
545
|
+
// 发送请求,会使用代理管理器选择的代理
|
|
546
|
+
// 换下一条需要 rotateOnError: true
|
|
544
547
|
const response = await sdk.post('http://your-api.com/request', {
|
|
545
548
|
url: 'https://api.example.com/data',
|
|
546
549
|
method: 'GET',
|
|
@@ -579,7 +582,7 @@ const response = await sdk.post('http://your-api.com/request', {
|
|
|
579
582
|
|
|
580
583
|
#### 6. 异常时自动轮换
|
|
581
584
|
|
|
582
|
-
|
|
585
|
+
默认不换代理。设置 `rotateOnError: true` 后,网关返回的上游代理错误(代理认证、SOCKS、连接被拒绝、超时)才会换下一条并重试。连不上本次请求 URL 本身(网关不可达)不会记到代理凭证上。
|
|
583
586
|
|
|
584
587
|
```typescript
|
|
585
588
|
const sdk = await createProxyRequest({
|
|
@@ -589,7 +592,8 @@ const sdk = await createProxyRequest({
|
|
|
589
592
|
'proxy3.example.com:8080:user3:pass3'
|
|
590
593
|
],
|
|
591
594
|
proxyStrategy: 'failover', // 推荐使用故障转移策略
|
|
592
|
-
|
|
595
|
+
rotateOnError: true,
|
|
596
|
+
maxRetries: 3 // 最多重试3次,开启 rotateOnError 后每次上游代理失败会换下一条
|
|
593
597
|
});
|
|
594
598
|
|
|
595
599
|
// 如果 proxy1 失败,会自动尝试 proxy2,再失败会尝试 proxy3
|
|
@@ -620,12 +624,11 @@ const response = await sdk.get('https://api.example.com/data');
|
|
|
620
624
|
|
|
621
625
|
**故障检测:**
|
|
622
626
|
|
|
623
|
-
|
|
627
|
+
`rotateOnError: true` 时,按网关响应体判断上游代理失败并换凭证:
|
|
624
628
|
|
|
625
|
-
-
|
|
626
|
-
-
|
|
627
|
-
-
|
|
628
|
-
- HTTP 错误(根据配置)
|
|
629
|
+
- 代理认证失败(407)
|
|
630
|
+
- 响应里带有 proxy / socks / tunnel
|
|
631
|
+
- 状态码 408、502、503,且错误文案是超时、连接被拒绝、域名无法解析
|
|
629
632
|
|
|
630
633
|
**代理状态管理:**
|
|
631
634
|
|
package/dist/Request.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export declare class Request {
|
|
|
9
9
|
private readonly retryDelay;
|
|
10
10
|
private readonly retryDelayBase;
|
|
11
11
|
private readonly retryDelayMultiplier;
|
|
12
|
+
private readonly rotateOnError;
|
|
12
13
|
constructor(options?: RequestInitOptions);
|
|
13
14
|
/**
|
|
14
15
|
* 设置日志等级
|
|
@@ -53,6 +54,9 @@ export declare class Request {
|
|
|
53
54
|
* 检查是否启用了代理管理功能
|
|
54
55
|
*/
|
|
55
56
|
hasProxyManagement(): boolean;
|
|
57
|
+
private shouldSwitchCredential;
|
|
58
|
+
private noteCredentialFailure;
|
|
59
|
+
private waitBeforeRetry;
|
|
56
60
|
}
|
|
57
61
|
export default Request;
|
|
58
62
|
//# sourceMappingURL=Request.d.ts.map
|
package/dist/Request.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Request.d.ts","sourceRoot":"","sources":["../src/Request.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,YAAY,EAEZ,UAAU,EACV,QAAQ,EACT,MAAM,SAAS,CAAC;AAIj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AC,qBAAqB;YAMf,eAAe;CAW9B;AAgCD,eAAe,OAAO,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{"use strict";var e={171:e=>{e.exports=require("winston-daily-rotate-file")},298:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getFormattedDate=function(e=!1){const t=new Date,r=t.getFullYear(),s=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0");return e?`${r}-${s}-${n} ${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}:${String(t.getSeconds()).padStart(2,"0")}`:`${r}-${s}-${n}`},t.getMainDirectory=function(){const e=r(928);return r.c[r.s]?e.dirname(r.c[r.s].filename):process.cwd()}},306:e=>{e.exports=require("winston")},330:e=>{e.exports=JSON.parse('{"name":"proxy-pool-manager","version":"1.0.10","description":"proxy manager","main":"./dist/index.cjs","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"import":"./dist/index.mjs","require":"./dist/index.cjs","types":"./dist/index.d.ts"}},"files":["dist","package.json"],"scripts":{"build":"webpack --mode=production && tsc --emitDeclarationOnly --outDir dist && node scripts/generate-esm-wrapper.js","dev":"webpack --mode=development","watch":"webpack --watch --mode=development","build:analyze":"webpack --mode=production --analyze","prepublishOnly":"npm run build"},"author":"memeak","license":"ISC","devDependencies":{"@types/node":"^22.5.4","@webpack-cli/generators":"^3.0.7","clean-webpack-plugin":"^4.0.0","ts-loader":"^9.5.1","typescript":"^5.6.2","webpack":"^5.94.0","webpack-cli":"^5.1.4"},"dependencies":{"async":"^3.2.6","node-fetch":"^2.7.0","winston":"^3.18.3","winston-daily-rotate-file":"^5.0.0"},"packageManager":"pnpm@10.18.2+sha512.9fb969fa749b3ade6035e0f109f0b8a60b5d08a1a87fdf72e337da90dcc93336e2280ca4e44f2358a649b83c17959e9993e777c2080879f3801e6f0d999ad3dd"}')},378:function(e,t,r){var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.Request=void 0;const n=s(r(867)),i=r(388);class o{constructor(e={}){if(this.proxyManager=null,this.hasProxyManager=!1,void 0!==e.maxRetries&&(e.maxRetries<0||!Number.isInteger(e.maxRetries)))throw new Error("maxRetries 必须是非负整数");if(void 0!==e.timeout&&e.timeout<=0)throw new Error("timeout 必须是正数");if(void 0!==e.retryDelay&&e.retryDelay<0)throw new Error("retryDelay 必须是非负数");if(void 0!==e.retryDelayBase&&e.retryDelayBase<=0)throw new Error("retryDelayBase 必须是正数");if(void 0!==e.retryDelayMultiplier&&e.retryDelayMultiplier<=0)throw new Error("retryDelayMultiplier 必须是正数");this.maxRetries=e.maxRetries??3,this.timeout=e.timeout??30,this.logLevel=e.logLevel||"none",this.proxyStrategy=e.proxyStrategy||"sequential",this.retryDelay=e.retryDelay??null,this.retryDelayBase=e.retryDelayBase??1e3,this.retryDelayMultiplier=e.retryDelayMultiplier??2;try{const t=e.instanceId||"default";this.proxyManager=i.ServiceLocator.get(`ProxyManager-${t}`),this.hasProxyManager=!0,this.log("info","成功获取 ProxyManager 实例",{instanceId:t})}catch(t){this.hasProxyManager=!1,this.log("info","ProxyManager 未初始化,将以轻量级模式运行(不使用代理管理功能)",{instanceId:e.instanceId||"default"})}}setLogLevel(e){try{i.ServiceLocator.get("DebugManager").setLogLevel(e),this.log("info",`设置日志等级: ${e}`)}catch(e){console.warn("DebugManager未注册,无法设置日志等级")}}getLogLevel(){try{return i.ServiceLocator.get("DebugManager").getLogLevel()}catch(e){return"info"}}log(e,t,r){try{const s=i.ServiceLocator.get("DebugManager");e.toUpperCase(),s.log(e,`[Request] ${t}`,r)}catch(s){const n=`[${e.toUpperCase()}]`;("error"===e?console.error:"warn"===e?console.warn:"debug"===e||"verbose"===e?console.debug:console.info)(`${n} [Request] ${t}`,r||"")}}async selectProxy(e){if(!0===e.options.noProxy)return this.log("info","noProxy 为 true,强制直连",{}),null;if(e.options.proxy){const t=e.options.proxy;return this.hasProxyManager&&this.proxyManager&&await this.proxyManager.addProxy(t).catch(()=>{}),this.log("info","使用请求级别代理",{proxy:t}),t}if(!this.hasProxyManager||!this.proxyManager)return null;const t=this.proxyManager.getProxiesCount();if(0===t)return null;const r=this.proxyManager.getAvailableProxy();return r&&this.log("info","使用策略选择代理",{proxy:r,strategy:this.proxyManager.getProxyStrategy(),index:this.proxyManager.getCurrentProxyIndex()+1,total:t}),r}async executeSingleRequest(e,t){const r=e.options.timeout||this.timeout,s=1e3*r;try{const i=await this.selectProxy(e),o={method:e.method,headers:{},signal:AbortSignal.timeout(s)},a=e.options?{...e.options}:{};i&&(a.proxy=i),Object.keys(a).length>0&&(o.body=JSON.stringify(a),o.headers["Content-Type"]="application/json"),this.log("info",`开始请求 ${e.url} (尝试 ${t}/${this.maxRetries})`,{method:e.method,timeout:r,hasProxy:!!i});const c=Date.now(),l=await(0,n.default)(e.url,o),u=Date.now()-c;if(!l.ok)throw new Error(`HTTP Error: ${l.status} ${l.statusText}`);const h=await l.text();let g;try{g=JSON.parse(h)}catch{g=h}const y={status_code:l.status,success:l.ok,headers:Object.fromEntries(l.headers.entries()),data:g,error:l.ok?void 0:h,timestamp:(new Date).toISOString()};if(this.hasProxyManager&&this.proxyManager){const e=this.proxyManager.getCurrentProxy();e&&await this.proxyManager.recordProxyUsage(e,y.success,u).catch(()=>{})}return y}catch(s){if("TimeoutError"===s.name||"AbortError"===s.name)throw this.log("warn",`请求超时 (${r}s)`,{url:e.url,attempt:t}),new Error(`请求超时: ${r}秒`);if(this.hasProxyManager&&this.proxyManager){const e=this.proxyManager.getCurrentProxy();e&&this.proxyManager.shouldRotateProxy(s)&&(this.log("error",`代理 ${e} 出现问题,尝试轮换`,{error:s.message}),await this.proxyManager.rotateProxy().catch(()=>{}))}throw s}}isValidStatusCode(e){return e>=200&&e<300}async get(e,t={}){let r=e;return t.params&&Object.keys(t.params).length>0&&(r=`${e}?${new URLSearchParams(t.params).toString()}`),this.request({url:r,method:"GET",options:t})}async post(e,t={}){return this.request({url:e,method:"POST",options:t})}async put(e,t={}){return this.request({url:e,method:"PUT",options:t})}async delete(e,t={}){return this.request({url:e,method:"DELETE",options:t})}async patch(e,t={}){return this.request({url:e,method:"PATCH",options:t})}async request(e){const t={url:e.url,method:e.method,options:{...e.options,timeout:e.options.timeout||this.timeout}};for(let e=1;e<=this.maxRetries;e++)try{const r=await this.executeSingleRequest(t,e),s={status:r.status_code,statusText:this.getStatusText(r.status_code),headers:r.headers||{},error:r.error?String(r.error):null,errors:[],data:r.data,text:()=>"string"==typeof r.data?r.data:JSON.stringify(r.data),json:()=>r.data,buffer:()=>Buffer.from("string"==typeof r.data?r.data:JSON.stringify(r.data||{}))};return this.log("info","请求成功",{url:t.url,status:s.status,attempt:e}),s}catch(r){const s=r.message;if(this.log("error","请求失败",{attempt:e,maxRetries:this.maxRetries,url:t.url,error:s}),(s.includes("超时")||"TimeoutError"===r.name)&&this.log("warn",`请求超时,尝试 ${e}/${this.maxRetries}`),!t.options.noProxy&&this.hasProxyManager&&this.proxyManager&&e<this.maxRetries){if(0===this.proxyManager.getAvailableProxiesList().length){this.log("warn","无可用代理,停止重试");break}if(!t.options.proxy&&this.proxyManager.shouldRotateProxy(r)){const e=await this.proxyManager.rotateProxy().catch(()=>null);e&&this.log("info",`代理轮换成功,使用新代理: ${e}`)}}if(e<this.maxRetries){let t;null!==this.retryDelay?(t=this.retryDelay,this.log("info",`等待 ${t}ms 后重试(固定间隔)`)):(t=this.retryDelayBase*Math.pow(this.retryDelayMultiplier,e-1),this.log("info",`等待 ${t}ms 后重试(指数退避:基础 ${this.retryDelayBase}ms,倍数 ${this.retryDelayMultiplier})`)),await new Promise(e=>setTimeout(e,t))}}throw new Error(`${e.options.url} 请求失败,已尝试 ${this.maxRetries} 次都失败了`)}getStatusText(e){return{200:"OK",201:"Created",202:"Accepted",204:"No Content",400:"Bad Request",401:"Unauthorized",403:"Forbidden",404:"Not Found",500:"Internal Server Error",502:"Bad Gateway",503:"Service Unavailable"}[e]||`Status ${e}`}getCurrentProxy(){return this.hasProxyManager&&this.proxyManager?this.proxyManager.getCurrentProxy():null}async rotateProxy(){if(!this.hasProxyManager||!this.proxyManager)throw new Error("ProxyManager 未初始化,无法轮换代理");return await this.proxyManager.rotateProxy()}resetProxyUsage(){this.hasProxyManager&&this.proxyManager&&this.proxyManager.resetProxyUsage()}setProxyStrategy(e){if(!this.hasProxyManager||!this.proxyManager)throw new Error("ProxyManager 未初始化,无法设置代理策略");this.proxyManager.setProxyStrategy(e)}async checkProxy(e){if(!this.hasProxyManager||!this.proxyManager)throw new Error("ProxyManager 未初始化,无法检查代理");return this.proxyManager.checkProxy(e)}getAvailableProxiesList(){return this.hasProxyManager&&this.proxyManager?this.proxyManager.getAvailableProxiesList():[]}hasProxyManagement(){return this.hasProxyManager}}t.Request=o,t.default=o},388:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ServiceLocator=void 0;class r{static shouldLog(e){try{if(this.services.has("DebugManager")){const t=this.services.get("DebugManager");if(t&&"function"==typeof t.getLogLevel){const r=t.getLogLevel(),s={none:0,error:1,warn:2,info:3,debug:4,verbose:5},n=s[r]||0;return(s[e]||0)<=n}}}catch(e){}return"error"===e||"warn"===e}static shouldLogForService(e,t){if(["DebugManager","AsyncQueue"].includes(e)&&("debug"===t||"verbose"===t)){try{if(this.services.has("DebugManager")){const e=this.services.get("DebugManager");if(e&&"function"==typeof e.getLogLevel)return"verbose"===e.getLogLevel()}}catch(e){}return!1}return this.shouldLog(t)}static get(e){if(this.services.has(e)){const t=this.services.get(e);return this.shouldLogForService(e,"debug")&&this.log("debug",`返回已注册的服务实例: ${e}`,{serviceType:this.getServiceType(t)}),t}if(this.dependencies.has(e)){this.shouldLogForService(e,"debug")&&this.log("debug",`通过工厂创建服务: ${e}`);const t=this.dependencies.get(e)();return this.services.set(e,t),this.shouldLogForService(e,"debug")&&this.log("debug",`工厂创建服务完成: ${e}`,{serviceType:this.getServiceType(t)}),t}const t=new Error(`[ServiceLocator] 服务未注册: ${e}`);throw this.log("error","服务未注册",{serviceName:e,availableServices:this.getAvailableServiceNames(),error:t.message}),t}static has(e){const t=this.services.has(e)||this.dependencies.has(e);return this.shouldLogForService(e,"debug")&&this.log("debug",`检查服务存在性: ${e}`,{exists:t,hasInstance:this.services.has(e),hasFactory:this.dependencies.has(e)}),t}static register(e,t){this.services.set(e,t),this.shouldLogForService(e,"info")&&this.log("info",`注册服务: ${e}`,{serviceType:this.getServiceType(t),hasFactory:this.dependencies.has(e)})}static registerFactory(e,t){this.dependencies.set(e,t),this.shouldLogForService(e,"info")&&this.log("info",`注册服务工厂: ${e}`,{hasExistingInstance:this.services.has(e)})}static log(e,t,r){if(!this.shouldLog(e))return;try{if(this.services.has("DebugManager")){const s=this.services.get("DebugManager");if(s&&"function"==typeof s.log)return e.toUpperCase(),void s.log(e,`[ServiceLocator] ${t}`,r)}}catch(e){}const s=`[${e.toUpperCase()}]`;("error"===e?console.error:"warn"===e?console.warn:"debug"===e||"verbose"===e?console.debug:console.info)(`${s} [ServiceLocator] ${t}`,r||"")}static getAvailableServiceNames(){const e=Array.from(this.services.keys()),t=Array.from(this.dependencies.keys()),r=[...new Set([...e,...t])];return this.shouldLog("debug")&&this.log("debug","获取可用服务名称",{total:r.length,services:e,factories:t}),r}static getStats(){const e=Array.from(this.services.keys()),t=Array.from(this.dependencies.keys()),r={totalServices:e.length,totalFactories:t.length,serviceNames:e,factoryNames:t};return this.shouldLog("debug")&&this.log("debug","服务统计",r),r}static isInitialized(){const e=this.has("DebugManager");return this.shouldLog("debug")&&this.log("debug","检查服务定位器初始化状态",{hasDebugManager:e,totalServices:this.services.size,totalFactories:this.dependencies.size}),e}static getServiceType(e){return e?e.constructor&&e.constructor.name?e.constructor.name:"function"==typeof e?"Function":Array.isArray(e)?"Array":"object"==typeof e?"Object":typeof e:"null"}static registerMultiple(e){const t=Object.keys(e);this.log("info","批量注册服务",{count:t.length,services:t}),Object.entries(e).forEach(([e,t])=>{this.register(e,t)})}static safeGet(e,t){try{return this.get(e)}catch(r){return this.log("warn",`安全获取服务失败: ${e}`,{error:r.message,usingDefault:void 0!==t}),t}}static reset(){this.services.clear(),this.dependencies.clear(),this.log("info","服务定位器已重置")}static initialize(){this.log("info","服务定位器初始化",{nodeEnv:"production"})}static clear(){const e=this.services.size,t=this.dependencies.size;this.services.clear(),this.dependencies.clear(),this.log("info","所有服务已清除",{clearedServices:e,clearedFactories:t})}static removeService(e){const t=this.services.has(e),r=this.dependencies.has(e);return this.services.delete(e),this.dependencies.delete(e),!(!t&&!r||(this.log("info",`移除服务: ${e}`,{hadService:t,hadFactory:r}),0))}static getExistingInstance(e){if(this.services.has(e))return this.services.get(e)}static hasOnlyFactory(e){return!this.services.has(e)&&this.dependencies.has(e)}static getCounts(){const e=this.services.size,t=this.dependencies.size,r=e+t;return this.shouldLog("debug")&&this.log("debug","服务数量统计",{instances:e,factories:t,total:r}),{instances:e,factories:t,total:r}}}t.ServiceLocator=r,r.services=new Map,r.dependencies=new Map},435:function(e,t,r){var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getMainDirectory=t.getFormattedDate=t.VERSION=t.ProxyRequestSDK=t.AsyncQueueSingleton=t.DebugManager=t.ServiceLocator=t.ProxyManager=t.Request=void 0,t.initializeServices=h,t.createProxyRequest=async function(e){return await h(e)},t.registerCoreServices=function(e={}){const t=e.instanceId||`core-${Date.now()}`,r=c.DebugManager.getInstance();e.logLevel&&r.setLogLevel(e.logLevel),a.ServiceLocator.register("DebugManager",r);const s=l.AsyncQueueSingleton.getInstance(t,{logLevel:e.logLevel});a.ServiceLocator.register(`AsyncQueue-${t}`,s);const n=o.ProxyManager.getInstance({proxies:e.proxies,proxy:e.proxy,logLevel:e.logLevel,instanceId:t});a.ServiceLocator.register(`ProxyManager-${t}`,n);const u=new i.Request({logLevel:e.logLevel,instanceId:t});a.ServiceLocator.register(`Request-${t}`,u)},t.registerRequestFactory=function(e,t){const r=t||`factory-${Date.now()}`;a.ServiceLocator.registerFactory(`Request-${r}`,e)},t.registerProxyManagerFactory=function(e,t){const r=t||`factory-${Date.now()}`;a.ServiceLocator.registerFactory(`ProxyManager-${r}`,e)},t.getStandaloneServices=function(e={}){const t=e.instanceId||`standalone-${Date.now()}`,r=l.AsyncQueueSingleton.getInstance(`standalone-${t}`,{logLevel:e.logLevel});return{proxyManager:o.ProxyManager.getInstance({proxies:e.proxies,proxy:e.proxy,logLevel:e.logLevel,instanceId:t}),request:new i.Request({logLevel:e.logLevel,instanceId:t}),asyncQueue:r}},t.cleanupServices=function(){a.ServiceLocator.clear(),l.AsyncQueueSingleton.destroyAllInstances(),o.ProxyManager.resetInstance()},t.checkServicesHealth=async function(e){try{const t=e||"default",r={DebugManager:a.ServiceLocator.has("DebugManager"),[`ProxyManager-${t}`]:a.ServiceLocator.has(`ProxyManager-${t}`),[`Request-${t}`]:a.ServiceLocator.has(`Request-${t}`),[`AsyncQueue-${t}`]:a.ServiceLocator.has(`AsyncQueue-${t}`)},s=l.AsyncQueueSingleton.getInstanceNames();return{proxyManager:a.ServiceLocator.has(`ProxyManager-${t}`),asyncQueues:s,services:r}}catch(e){return{proxyManager:!1,asyncQueues:[],services:{}}}};const n=s(r(330)),i=r(378);Object.defineProperty(t,"Request",{enumerable:!0,get:function(){return i.Request}});const o=r(696);Object.defineProperty(t,"ProxyManager",{enumerable:!0,get:function(){return o.ProxyManager}});const a=r(388);Object.defineProperty(t,"ServiceLocator",{enumerable:!0,get:function(){return a.ServiceLocator}});const c=r(577);Object.defineProperty(t,"DebugManager",{enumerable:!0,get:function(){return c.DebugManager}});const l=r(892);Object.defineProperty(t,"AsyncQueueSingleton",{enumerable:!0,get:function(){return l.AsyncQueueSingleton}});class u{constructor(e){this.proxyManagerInstance=null,this.isInitialized=!1,this.instanceId=e.instanceId||`sdk-${Date.now()}`,e.logLevel&&this.setLogLevel(e.logLevel);const t=!!(e.proxies&&e.proxies.length>0)||!!e.proxy;if((e.proxyCheckOptions||t)&&!t&&!e.proxyCheckOptions?.mainUrl&&!1!==e.proxyCheckEnabled)throw new Error("启用代理管理功能时,proxyCheckOptions.mainUrl 必须设置(除非 proxyCheckEnabled 为 false 或提供了代理数组)");if(!a.ServiceLocator.has("DebugManager")){const t=c.DebugManager.getInstance();e.logLevel&&t.setLogLevel(e.logLevel),a.ServiceLocator.register("DebugManager",t),this.log("info","注册 DebugManager")}if(!a.ServiceLocator.has(`AsyncQueue-${this.instanceId}`)){const t=l.AsyncQueueSingleton.getInstance(this.instanceId,{logLevel:e.logLevel});a.ServiceLocator.register(`AsyncQueue-${this.instanceId}`,t),this.log("info","注册 AsyncQueue",{instanceId:this.instanceId})}try{if(!a.ServiceLocator.has(`Request-${this.instanceId}`))throw new Error("Request 服务未注册。请使用 createProxyRequest() 或 initializeServices() 创建 SDK 实例,不要直接 new ProxyRequestSDK()。");this.requestInstance=a.ServiceLocator.get(`Request-${this.instanceId}`),a.ServiceLocator.has(`ProxyManager-${this.instanceId}`)?(this.proxyManagerInstance=a.ServiceLocator.get(`ProxyManager-${this.instanceId}`),this.log("info","使用已注册的服务实例(包含代理管理)",{instanceId:this.instanceId})):(this.proxyManagerInstance=null,this.log("info","使用已注册的服务实例(轻量级模式,无代理管理)",{instanceId:this.instanceId}))}catch(e){const t=e?.message||String(e);if(t.includes("请使用 createProxyRequest"))throw e;throw this.log("error","服务未正确初始化",{error:t}),new Error(`服务初始化失败: ${t}。请使用 createProxyRequest() 或 initializeServices() 创建实例。`)}this.initializeAsync(e).catch(e=>{console.error("SDK初始化失败:",e)})}log(e,t,r){try{const s=a.ServiceLocator.get("DebugManager");e.toUpperCase(),s.log(e,`[ProxyRequestSDK:${this.instanceId}] ${t}`,r)}catch(s){const n=`[${e.toUpperCase()}]`;("error"===e?console.error:"warn"===e?console.warn:"debug"===e?console.debug:console.info)(`${n} [ProxyRequestSDK:${this.instanceId}] ${t}`,r||"")}}async initializeAsync(e){try{this.proxyManagerInstance&&await this.proxyManagerInstance.waitForInitialization(),this.isInitialized=!0,this.log("info","初始化完成",{hasProxyManagement:!!this.proxyManagerInstance})}catch(e){throw this.log("error","初始化失败:",e),e}}async waitForReady(){for(;!this.isInitialized;)await new Promise(e=>setTimeout(e,100))}setLogLevel(e){try{a.ServiceLocator.get("DebugManager").setLogLevel(e),this.log("info",`设置日志等级: ${e}`)}catch(e){console.warn("DebugManager未注册,无法设置日志等级")}}getLogLevel(){try{return a.ServiceLocator.get("DebugManager").getLogLevel()}catch(e){return"info"}}getServiceInfo(){const e=["DebugManager",`ProxyManager-${this.instanceId}`,`Request-${this.instanceId}`,`AsyncQueue-${this.instanceId}`],t={};return e.forEach(e=>{t[e]=a.ServiceLocator.has(e)}),l.AsyncQueueSingleton.getInstanceNames().forEach(e=>{t[`AsyncQueue:${e}`]=!0}),t.hasProxyManagement=this.hasProxyManagement(),t}async get(e,t,r){await this.waitForReady();const s={...r,params:t?{...r?.params,...t}:r?.params};return this.requestInstance.get(e,s)}async post(e,t){return await this.waitForReady(),this.requestInstance.post(e,t)}async put(e,t){return await this.waitForReady(),this.requestInstance.put(e,t)}async delete(e,t){return await this.waitForReady(),this.requestInstance.delete(e,t)}async patch(e,t){return await this.waitForReady(),this.requestInstance.patch(e,t)}async request(e){return await this.waitForReady(),this.requestInstance.request({url:e.url,method:e.method||"GET",options:e.options||{}})}async addProxy(e){if(await this.waitForReady(),!this.proxyManagerInstance)throw new Error("代理管理功能未启用,请提供 proxies 或 proxyCheckOptions 来启用此功能");return this.proxyManagerInstance.addProxy(e)}async deleteProxy(e){if(await this.waitForReady(),!this.proxyManagerInstance)throw new Error("代理管理功能未启用,请提供 proxies 或 proxyCheckOptions 来启用此功能");return this.proxyManagerInstance.deleteProxy(e)}getAvailableProxies(){return this.proxyManagerInstance?this.proxyManagerInstance.getAvailableProxiesList():[]}getCurrentProxy(){return this.proxyManagerInstance?this.proxyManagerInstance.getCurrentProxy():null}async rotateProxy(){if(await this.waitForReady(),!this.proxyManagerInstance)throw new Error("代理管理功能未启用,请提供 proxies 或 proxyCheckOptions 来启用此功能");return this.proxyManagerInstance.rotateProxy()}setProxyStrategy(e){if(!this.proxyManagerInstance)throw new Error("代理管理功能未启用,请提供 proxies 或 proxyCheckOptions 来启用此功能");this.proxyManagerInstance.setProxyStrategy(e)}async checkProxy(e){if(await this.waitForReady(),!this.proxyManagerInstance)throw new Error("代理管理功能未启用,请提供 proxies 或 proxyCheckOptions 来启用此功能");return this.proxyManagerInstance.checkProxy(e)}async triggerProxyCheck(){if(await this.waitForReady(),!this.proxyManagerInstance)throw new Error("代理管理功能未启用,请提供 proxies 或 proxyCheckOptions 来启用此功能");return this.proxyManagerInstance.triggerProxyCheck()}hasProxyManagement(){return!!this.proxyManagerInstance}async getProxyStats(){if(await this.waitForReady(),!this.proxyManagerInstance)return{total:0,valid:0,invalid:0,available:0};const e=this.getAvailableProxies(),t=this.proxyManagerInstance?this.proxyManagerInstance.getProxiesCount():0;return{total:t,valid:e.length,invalid:t-e.length,available:e.length}}getProxyDetails(e){if(this.proxyManagerInstance)return this.proxyManagerInstance.getProxyDetails(e)}getQueueStats(){if(!this.proxyManagerInstance)throw new Error("代理管理功能未启用,无法获取队列统计");return this.proxyManagerInstance.getQueueStats()}getInstanceId(){return this.instanceId}async destroy(){this.log("info","开始清理资源"),[`ProxyManager-${this.instanceId}`,`Request-${this.instanceId}`,`AsyncQueue-${this.instanceId}`].forEach(e=>{a.ServiceLocator.has(e)&&(a.ServiceLocator.removeService(e),this.log("info",`清理服务: ${e}`))}),l.AsyncQueueSingleton.destroyInstance(this.instanceId),this.proxyManagerInstance&&(await this.proxyManagerInstance.destroy(),this.proxyManagerInstance=null),this.isInitialized=!1,this.log("info","资源清理完成")}}async function h(e){const t=e.instanceId||`instance-${Date.now()}`,r=!!(e.proxies&&e.proxies.length>0)||!!e.proxy,s=!(!e.proxyCheckOptions&&!r);if(s&&!r&&void 0===e.proxyCheckOptions?.mainUrl&&!1!==e.proxyCheckEnabled)throw new Error("启用代理管理功能时,proxyCheckOptions.mainUrl 必须设置(除非 proxyCheckEnabled 为 false 或提供了代理数组)");let n;[`ProxyManager-${t}`,`Request-${t}`,`AsyncQueue-${t}`].forEach(e=>{if(a.ServiceLocator.has(e)){if(e.startsWith("ProxyManager-"))try{const t=a.ServiceLocator.get(e);t&&"function"==typeof t.destroy&&t.destroy().catch(e=>{console.warn(`清理 ProxyManager 失败: ${e.message}`)})}catch(e){console.warn(`获取 ProxyManager 服务失败: ${e.message}`)}if(e.startsWith("AsyncQueue-")){const t=e.replace("AsyncQueue-","");l.AsyncQueueSingleton.destroyInstance(t)}a.ServiceLocator.removeService(e)}}),a.ServiceLocator.initialize(),a.ServiceLocator.has("DebugManager")?(n=a.ServiceLocator.get("DebugManager"),e.logLevel&&n.setLogLevel(e.logLevel)):(n=c.DebugManager.getInstance(),e.logLevel&&n.setLogLevel(e.logLevel),a.ServiceLocator.register("DebugManager",n));const h=`AsyncQueue-${t}`;let g;if(l.AsyncQueueSingleton.hasInstance(t)){if(g=l.AsyncQueueSingleton.getExistingInstance(t),g&&void 0!==e.logLevel)try{const t=a.ServiceLocator.get("DebugManager");e.logLevel&&t.setLogLevel(e.logLevel)}catch(e){console.warn("DebugManager未注册,无法更新debug状态")}}else g=l.AsyncQueueSingleton.getInstance(t,{logLevel:e.logLevel});a.ServiceLocator.register(h,g);let y=null;const d=`ProxyManager-${t}`;if(s)a.ServiceLocator.has(d)?(y=a.ServiceLocator.get(d),e.proxyStrategy&&y.setProxyStrategy(e.proxyStrategy),e.maxConcurrentChecks&&y.setMaxConcurrentChecks(e.maxConcurrentChecks)):y=o.ProxyManager.getInstance({proxies:e.proxies,proxy:e.proxy,proxyStrategy:e.proxyStrategy,maxConcurrentChecks:e.maxConcurrentChecks,logLevel:e.logLevel,proxyCheckOptions:e.proxyCheckOptions,proxyCheckEnabled:e.proxyCheckEnabled,instanceId:t}),await y.waitForInitialization(),a.ServiceLocator.register(d,y);else try{a.ServiceLocator.get("DebugManager").log("info","以轻量级模式运行(不使用代理管理功能)",{instanceId:t})}catch(e){console.info("以轻量级模式运行(不使用代理管理功能)",{instanceId:t})}const p=`Request-${t}`;let x;if(x=a.ServiceLocator.has(p)?a.ServiceLocator.get(p):new i.Request({maxRetries:e.maxRetries,timeout:e.timeout,logLevel:e.logLevel,retryDelay:e.retryDelay,retryDelayBase:e.retryDelayBase,retryDelayMultiplier:e.retryDelayMultiplier,instanceId:t}),a.ServiceLocator.register(p,x),e.logLevel&&"none"!==e.logLevel&&"error"!==e.logLevel)try{a.ServiceLocator.get("DebugManager").log("info","服务初始化完成",{instanceId:t,hasProxyManagement:s,proxyCount:y?y.getProxiesCount():0})}catch(e){console.info("服务初始化完成",{instanceId:t,hasProxyManagement:s,proxyCount:y?y.getProxiesCount():0})}return new u({...e,instanceId:t})}t.ProxyRequestSDK=u,t.default=u,t.VERSION=n.default.version;var g=r(298);Object.defineProperty(t,"getFormattedDate",{enumerable:!0,get:function(){return g.getFormattedDate}}),Object.defineProperty(t,"getMainDirectory",{enumerable:!0,get:function(){return g.getMainDirectory}})},577:function(e,t,r){var s,n=this&&this.__createBinding||(Object.create?function(e,t,r,s){void 0===s&&(s=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,s,n)}:function(e,t,r,s){void 0===s&&(s=r),e[s]=t[r]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||(s=function(e){return s=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},s(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=s(e),o=0;o<r.length;o++)"default"!==r[o]&&n(t,e,r[o]);return i(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.safeLog=t.debugManager=t.DebugManager=void 0;const a=o(r(896)),c=o(r(928)),l=o(r(306));r(171);class u{constructor(){this.logLevel="info",this.logLevelPriority={none:0,error:1,warn:2,info:3,debug:4,verbose:5},this.initializeLogger()}static getInstance(){return u.instance||(u.instance=new u),u.instance}initializeLogger(){const e=c.join(process.cwd(),"logs");a.existsSync(e)||a.mkdirSync(e,{recursive:!0});const t=l.format.combine(l.format.timestamp({format:"YYYY-MM-DD HH:mm:ss"}),l.format.printf(({timestamp:e,level:t,message:r,...s})=>{let n=`${e} [${t.toUpperCase()}] ${r}`;if(Object.keys(s).length>0){const{timestamp:e,level:t,message:r,...i}=s;if(Object.keys(i).length>0)try{n+=` | ${JSON.stringify(i)}`}catch{n+=` | ${String(i)}`}}return n}));this.logger=l.createLogger({level:this.getWinstonLevel(this.logLevel),format:t,transports:[new l.transports.Console({format:t}),new l.transports.DailyRotateFile({filename:c.join(e,"%DATE%.log"),format:t,datePattern:"YYYY/MM/DD",maxFiles:null})]})}getWinstonLevel(e){return{none:"error",error:"error",warn:"warn",info:"info",debug:"debug",verbose:"verbose"}[e]}setLogLevel(e){this.logLevel=e,this.logger.level=this.getWinstonLevel(e)}getLogLevel(){return this.logLevel}logInternal(e,t,r){const s=`[${e.toUpperCase()}]`;this.logger.log(this.getWinstonLevel(e),`${s} [DebugManager] ${t}`,r)}log(e,t,r){this.logger.log(this.getWinstonLevel(e),t,r)}error(e,t){this.log("error",e,t)}warn(e,t){this.log("warn",e,t)}info(e,t){this.log("info",e,t)}debug(e,t){this.log("debug",e,t)}verbose(e,t){this.log("verbose",e,t)}}t.DebugManager=u,t.debugManager=u.getInstance(),t.safeLog=t.debugManager.log.bind(t.debugManager)},626:e=>{e.exports=require("async")},696:function(e,t,r){var s,n=this&&this.__createBinding||(Object.create?function(e,t,r,s){void 0===s&&(s=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,s,n)}:function(e,t,r,s){void 0===s&&(s=r),e[s]=t[r]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||(s=function(e){return s=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},s(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=s(e),o=0;o<r.length;o++)"default"!==r[o]&&n(t,e,r[o]);return i(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.ProxyManager=void 0;const a=r(892),c=r(388);class l{constructor(e={}){this.isInitialized=!1,this.initializationPromise=null,this.instanceId=e.instanceId||`proxy-pool-manager-${Date.now()}`,this.logLevel=e.logLevel||"none",this.proxyCheckEnabled=e.proxyCheckEnabled??!0,this.proxyStrategy=e.proxyStrategy??"sequential",this.availableProxies=new Set,this.checkInProgress=new Set,this.maxConcurrentChecks=e.maxConcurrentChecks??5,this.asyncQueue=a.AsyncQueueSingleton.getInstance(this.instanceId,{concurrency:this.maxConcurrentChecks,autoStart:!0,logLevel:this.logLevel,onDrain:()=>{this.log("info","所有代理检测任务完成")},onError:e=>{this.log("error","代理检测任务出错:",e)},onSuccess:e=>{},taskHandler:async e=>(await new Promise(e=>setTimeout(e,1e3)),await this.taskHandler(e))}),this.proxies=[],Array.isArray(e.proxies)?e.proxies.forEach(e=>{this.addProxySync(e)}):e.proxy&&this.addProxySync(e.proxy),this.proxyCheckOptions={mainUrl:e.proxyCheckOptions?.mainUrl||"",testUrls:e.proxyCheckOptions?.testUrls??["http://httpbin.org/ip","http://api.ipify.org?format=json","http://ipinfo.io/json"],timeout:e.proxyCheckOptions?.timeout??5,successStatusCodes:e.proxyCheckOptions?.successStatusCodes??[200],checkInterval:e.proxyCheckOptions?.checkInterval??6e4,maxConsecutiveFails:e.proxyCheckOptions?.maxConsecutiveFails??3,maxResponseTime:e.proxyCheckOptions?.maxResponseTime??2e3},this.currentProxyIndex=0,this.usedProxies=new Set,this.initializationPromise=this.initializeAsync()}async initializeAsync(){try{this.isInitialized=!0,this.log("info",`ProxyManager初始化完成,加载了 ${this.proxies.length} 个代理`)}catch(e){throw this.log("error","ProxyManager初始化失败:",e),e}}async waitForInitialization(){if(!this.isInitialized){if(!this.initializationPromise)throw new Error("ProxyManager未正确初始化");await this.initializationPromise}}addProxySync(e){if(!this.proxies.find(t=>t.url===e)){const t={url:e,totalRequests:0,failCount:0,avgResponseTime:0,lastCheckTime:Date.now(),consecutiveFails:0,status:"valid"};this.proxies.push(t),this.availableProxies.add(e)}}static getInstance(e={}){const t=e.instanceId||`proxy-pool-manager-${Date.now()}`;if(l.instances.has(t))return l.instances.get(t);l.instanceLock=!0;try{if(l.instances.has(t))return l.instances.get(t);const r=new l({...e,instanceId:t});return l.instances.set(t,r),r}finally{l.instanceLock=!1}}static resetInstance(e){if(void 0!==e){const t=l.instances.get(e);t&&(t.destroy(),l.instances.delete(e))}else l.instances.forEach(e=>e.destroy()),l.instances.clear()}log(e,t,r){try{const s=c.ServiceLocator.get("DebugManager");e.toUpperCase(),s.log(e,`[ProxyManager] ${t}`,r)}catch(s){const n=`[${e.toUpperCase()}]`;("error"===e?console.error:"warn"===e?console.warn:"debug"===e||"verbose"===e?console.debug:console.info)(`${n} [ProxyManager] ${t}`,r||"")}}setLogLevel(e){try{c.ServiceLocator.get("DebugManager").setLogLevel(e),this.log("info",`设置日志等级: ${e}`)}catch(e){console.warn("DebugManager未注册,无法设置日志等级")}}getLogLevel(){try{return c.ServiceLocator.get("DebugManager").getLogLevel()}catch(e){return"info"}}async addProxy(e){if(!e?.trim())throw new Error("代理URL不能为空");await this.waitForInitialization();const t=this.proxies.find(t=>t.url===e);if(t)return this.log("info","代理已存在于内存中",{proxy:e}),t;const r={url:e,totalRequests:0,failCount:0,avgResponseTime:0,lastCheckTime:Date.now(),consecutiveFails:0,status:"valid"};return this.proxies.push(r),this.availableProxies.add(e),this.log("info","添加新代理",{proxy:e}),r}async deleteProxy(e){await this.waitForInitialization();const t=this.proxies.findIndex(t=>t.url===e);return-1!==t&&(this.proxies.splice(t,1),this.availableProxies.delete(e),this.log("info","从内存中删除代理",{proxy:e}),!0)}async deleteInvalidProxies(){await this.waitForInitialization();const e=this.proxies.filter(e=>"invalid"===e.status).length;return this.proxies=this.proxies.filter(e=>"valid"===e.status),this.availableProxies.clear(),this.proxies.forEach(e=>this.availableProxies.add(e.url)),this.log("info","从内存中删除无效代理",{count:e}),e}async standaloneProxyCheck(e,t,s,n){const{default:i}=await Promise.resolve().then(()=>o(r(867)));try{const r=new AbortController,o=setTimeout(()=>r.abort(),1e3*n),a={method:"POST",headers:{"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36"}};let c={url:s,method:"GET"};e&&(c.proxy=e,c.impersonate="chrome",c.timeout=n,a.body=JSON.stringify(c),a.headers["Content-Type"]="application/json");const l=await i(t,a),u=await l.text();let h;clearTimeout(o);try{h=JSON.parse(u)}catch{h=u}const g={status_code:l.status,success:l.ok,headers:Object.fromEntries(l.headers.entries()),data:h,error:l.ok?void 0:u,timestamp:(new Date).toISOString()},y=l.ok&&this.proxyCheckOptions.successStatusCodes.includes(g.status_code);return y?this.log("info","代理检测成功",{proxy:e,status:g.status_code,result:JSON.stringify(g.data)}):this.log("error","代理检测状态码不符",{proxy:e,statusCode:g.status_code,expected:this.proxyCheckOptions.successStatusCodes}),y}catch(t){return this.log("error","代理检测请求失败",{proxy:e,error:t.message}),!1}}async taskHandler(e){const t=Date.now();try{const r=this.proxyCheckOptions.testUrls[Math.floor(Math.random()*this.proxyCheckOptions.testUrls.length)],s=await this.standaloneProxyCheck(e.url,this.proxyCheckOptions.mainUrl,r,this.proxyCheckOptions.timeout),n=Date.now()-t;return e.totalRequests++,e.lastCheckTime=Date.now(),s?(e.avgResponseTime=(e.avgResponseTime*(e.totalRequests-1)+n)/e.totalRequests,e.consecutiveFails=0):(e.failCount++,e.consecutiveFails++),{proxy:e,isAvailable:s,responseTime:n}}catch(r){return this.log("error","代理检测出错",{proxy:e.url,error:r.message}),e.totalRequests++,e.failCount++,e.consecutiveFails++,e.lastCheckTime=Date.now(),{proxy:e,isAvailable:!1,responseTime:Date.now()-t}}}async checkAllProxies(){const e=this.proxies.filter(e=>"valid"===e.status);this.log("info",`开始批量检测代理,共 ${e.length} 个代理,最大并发数: ${this.maxConcurrentChecks}`),this.asyncQueue.updateConcurrency(this.maxConcurrentChecks);const t=[];try{const r=await this.asyncQueue.addBatch(e);t.push(...r),t.forEach(e=>{e.proxy.totalRequests>=2&&(e.proxy.failCount,e.proxy.totalRequests),e.proxy.failCount||e.proxy.avgResponseTime>this.proxyCheckOptions.maxResponseTime?(e.proxy.status="invalid",this.availableProxies.delete(e.proxy.url)):e.proxy.status="valid"});const s=e.filter(e=>"valid"===e.status).length,n=e.length-s;this.log("info","批量代理检测完成",{total:e.length,valid:s,invalid:n})}catch(e){this.log("error","批量代理检测失败",{error:e.message})}}getCurrentProxy(){return 0===this.proxies.length?null:this.proxies[this.currentProxyIndex].url}selectProxy(){const e=this.proxies.filter(e=>"valid"===e.status);if(0===e.length)return this.proxies.length>0?(this.currentProxyIndex=0,this.proxies[0].url):null;let t;switch(this.proxyStrategy){case"sequential":t=this.currentProxyIndex%e.length,this.currentProxyIndex=(t+1)%e.length;break;case"random":this.usedProxies.size>=e.length&&this.usedProxies.clear();const r=Array.from({length:e.length},(e,t)=>t).filter(e=>!this.usedProxies.has(e));t=r.length>0?r[Math.floor(Math.random()*r.length)]:Math.floor(Math.random()*e.length),this.usedProxies.add(t),this.currentProxyIndex=t;break;case"failover":const s=[...e].sort((e,t)=>{if(e.consecutiveFails!==t.consecutiveFails)return e.consecutiveFails-t.consecutiveFails;const r=e.totalRequests>0?e.failCount/e.totalRequests:0,s=t.totalRequests>0?t.failCount/t.totalRequests:0;return r!==s?r-s:e.avgResponseTime-t.avgResponseTime});t=this.proxies.findIndex(e=>e.url===s[0].url),this.currentProxyIndex=t;break;default:t=this.currentProxyIndex%e.length}return e[t].url}async rotateProxy(){if(0===this.proxies.filter(e=>"valid"===e.status).length)return this.proxies.length>0?(this.currentProxyIndex=0,this.log("info","无有效代理,默认使用第一个代理",{proxy:this.proxies[0].url}),this.proxies[0].url):null;const e=this.proxies[this.currentProxyIndex];e.failCount++,e.totalRequests++,e.consecutiveFails++,e.consecutiveFails>=this.proxyCheckOptions.maxConsecutiveFails&&(e.status="invalid",this.availableProxies.delete(e.url));const t=this.proxies.filter(e=>"valid"===e.status);if(0===t.length)return this.proxies.length>0?(this.currentProxyIndex=0,this.log("info","无有效代理,默认使用第一个代理",{proxy:this.proxies[0].url}),this.proxies[0].url):null;this.currentProxyIndex=(this.currentProxyIndex+1)%t.length;const r=t[this.currentProxyIndex];return this.log("info","轮换代理",{from:e.url,to:r.url,consecutiveFails:e.consecutiveFails}),r.url}async recordProxyUsage(e,t,r){const s=this.proxies.find(t=>t.url===e);s&&(s.totalRequests++,t?(s.avgResponseTime=(s.avgResponseTime*(s.totalRequests-1)+r)/s.totalRequests,s.consecutiveFails=0):(s.failCount++,s.consecutiveFails++),s.lastCheckTime=Date.now(),t&&"invalid"===s.status&&(s.status="valid",this.availableProxies.add(s.url)))}resetProxyUsage(){this.usedProxies.clear(),this.log("info","重置代理使用记录")}setProxyStrategy(e){this.proxyStrategy=e,this.resetProxyUsage(),this.log("info","设置代理策略",{strategy:e})}async enhancedProxyCheck(e){if(!this.proxyCheckEnabled)return!0;if(this.checkInProgress.has(e))return!0;try{this.checkInProgress.add(e);const t=this.proxyCheckOptions.testUrls[Math.floor(Math.random()*this.proxyCheckOptions.testUrls.length)],r=Date.now(),s=await this.standaloneProxyCheck(e,this.proxyCheckOptions.mainUrl,t,this.proxyCheckOptions.timeout),n=Date.now()-r;return s&&n>this.proxyCheckOptions.maxResponseTime?(this.log("error","代理响应时间过长",{proxy:e,responseTime:n,threshold:this.proxyCheckOptions.maxResponseTime}),!1):s}catch(t){return this.log("error","代理检测异常",{proxy:e,error:t.message}),!1}finally{this.checkInProgress.delete(e)}}setMaxConcurrentChecks(e){e>0&&(this.maxConcurrentChecks=e,this.asyncQueue.updateConcurrency(e),this.log("info","更新最大并发检查数",{maxConcurrentChecks:e}))}getQueueStats(){return this.asyncQueue.stats}pauseProxyChecks(){this.asyncQueue.pause(),this.log("info","代理检测队列已暂停")}resumeProxyChecks(){this.asyncQueue.resume(),this.log("info","代理检测队列已恢复")}async checkProxy(e){const t=e||this.getCurrentProxy();if(!t)return!1;const r=await this.enhancedProxyCheck(t),s=this.proxies.find(e=>e.url===t);return s&&(s.status=r?"valid":"invalid",r?this.availableProxies.add(t):this.availableProxies.delete(t)),this.log("info","代理检查完成",{proxy:t,result:r}),r}getAvailableProxy(){const e=this.proxies.filter(e=>"valid"===e.status);if(0===e.length)return this.proxies.length>0?(this.currentProxyIndex=0,this.log("info","所有代理均不可用,默认使用第一个代理",{proxy:this.proxies[0].url}),this.proxies[0].url):null;const t=this.selectProxy();return this.log("info","获取代理",{proxy:t,strategy:this.proxyStrategy,available:e.length}),t}shouldRotateProxy(e){if(0===this.proxies.filter(e=>"valid"===e.status).length)return!1;if(!e||!e.message)return!1;const t=e.message.toLowerCase();return["proxy","connect","connection","timeout","socket","网络","连接","ETIMEDOUT","ECONNREFUSED"].some(e=>t.includes(e))}async triggerProxyCheck(){await this.waitForInitialization(),this.log("info","手动触发代理检测"),await this.checkAllProxies()}getAvailableProxiesList(){const e=this.proxies.filter(e=>"valid"===e.status).map(e=>e.url);return 0===e.length&&this.proxies.length>0?[this.proxies[0].url]:e}getProxyDetails(e){return this.proxies.find(t=>t.url===e)}getProxiesCount(){return this.proxies.length}getProxyStrategy(){return this.proxyStrategy}getCurrentProxyIndex(){return this.currentProxyIndex}async destroy(){if(this.checkInProgress.clear(),this.usedProxies.clear(),this.proxies=[],this.availableProxies.clear(),this.asyncQueue){const e=this.asyncQueue.getName();this.asyncQueue.pause(),a.AsyncQueueSingleton.destroyInstance(e)}this.isInitialized=!1,this.initializationPromise=null,l.instances.delete(this.instanceId),this.log("info","ProxyManager 已完全销毁")}}t.ProxyManager=l,l.instances=new Map,l.instanceLock=!1},867:e=>{e.exports=require("node-fetch")},892:function(e,t,r){var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.AsyncQueueSingleton=void 0;const n=s(r(626)),i=r(388);class o{constructor(e="default",t={}){this.queue=null,this.isInitialized=!1,this.logLevel="info",this.instanceName=e,this.logLevel=t.logLevel||"info",this.concurrency=t.concurrency||100,this.autoStart=!1!==t.autoStart,this.onDrain=t.onDrain||(()=>{this.log("info","所有任务完成")}),this.onError=t.onError||(e=>{this.log("error","任务错误:",e)}),this.onSuccess=t.onSuccess||(e=>{}),this.taskHandler=t.taskHandler||this.defaultTaskHandler,this.initializeQueue()}async defaultTaskHandler(e){return await new Promise(e=>setTimeout(e,1e3)),this.log("debug",`[${this.instanceName}] 剩余任务${this.queue?.length()} 运行任务数${this.queue?.running()}`),`运行成功 - ${this.instanceName}`}initializeQueue(){this.isInitialized||(this.queue=n.default.queue(async e=>await this.taskHandler(e),this.concurrency),this.queue.drain(()=>{this.onDrain()}),this.autoStart||this.queue.pause(),this.isInitialized=!0,this.log("info","队列初始化完成",{concurrency:this.concurrency,autoStart:this.autoStart}))}add(e,t=0){return new Promise((r,s)=>{if(!this.queue)return void s(new Error(`[${this.instanceName}] 队列未初始化`));const n=(t,n)=>{t?(this.log("error","任务执行失败",{task:e,error:t.message}),s(t)):(this.onSuccess(n),r(n))};t>0?this.queue.unshift(e,n):this.queue.push(e,n),this.log("debug","添加任务",{task:e,priority:t,queueLength:this.queue.length(),running:this.queue.running()})})}addBatch(e,t=0){return this.log("info","批量添加任务",{count:e.length,priority:t,instance:this.instanceName}),Promise.all(e.map(e=>this.add(e,t)))}updateConcurrency(e){if(e>0&&e!==this.concurrency&&this.queue){const t=this.concurrency;this.concurrency=e,this.queue.concurrency=e,this.log("info","更新并发数",{from:t,to:e,instance:this.instanceName})}}pause(){return this.queue?.pause(),this.log("info","队列暂停",{instance:this.instanceName}),this}resume(){return this.queue?.resume(),this.log("info","队列恢复",{instance:this.instanceName}),this}get length(){return this.queue?.length()||0}get running(){return this.queue?.running()||0}get workersList(){return this.queue?.workersList()||[]}get idle(){return this.queue?.idle()||!1}get stats(){return{length:this.length,running:this.running,concurrency:this.concurrency,idle:this.idle}}getName(){return this.instanceName}setTaskHandler(e){this.taskHandler=e,this.log("info","任务处理器已更新",{instance:this.instanceName})}destroy(){this.queue&&(this.queue.kill(),this.queue=null),this.isInitialized=!1,this.log("info","队列已销毁",{instance:this.instanceName})}log(e,t,r){try{const s=i.ServiceLocator.get("DebugManager");e.toUpperCase(),s.log(e,`[AsyncQueue:${this.instanceName}] ${t}`,r)}catch(s){const n=`[${e.toUpperCase()}]`;("error"===e?console.error:"warn"===e?console.warn:"debug"===e||"verbose"===e?console.debug:console.info)(`${n} [AsyncQueue:${this.instanceName}] ${t}`,r||"")}}setLogLevel(e){this.logLevel=e;try{i.ServiceLocator.get("DebugManager").setLogLevel(e)}catch(e){console.warn("DebugManager未注册,无法设置日志等级")}this.log("info",`设置日志等级: ${e}`)}getLogLevel(){return this.logLevel}static getInstance(e="default",t={}){if(o.instances.has(e)){const r=o.instances.get(e);if(r.isInitialized&&r.queue)return void 0!==t.logLevel&&t.logLevel!==r.logLevel&&r.setLogLevel(t.logLevel),t.concurrency&&t.concurrency!==r.concurrency&&r.updateConcurrency(t.concurrency),r;o.instances.delete(e)}const r=new o(e,t);return o.instances.set(e,r),r}static getInstanceNames(){return Array.from(o.instances.keys())}static getAllInstancesStats(){const e={};return o.instances.forEach((t,r)=>{e[r]=t.stats}),e}static destroyInstance(e="default"){if(o.instances.has(e)){const t=o.instances.get(e);t?.isInitialized&&t.queue&&t.destroy(),o.instances.delete(e),console.log(`[AsyncQueue] 已销毁实例: ${e}`)}}static destroyAllInstances(){const e=Array.from(o.instances.keys());e.forEach(e=>{o.destroyInstance(e)}),console.log(`[AsyncQueue] 已销毁所有实例: ${e.join(", ")}`)}static hasInstance(e="default"){return o.instances.has(e)}static getExistingInstance(e="default"){return o.instances.get(e)||null}debug(e,t){this.log("debug",e,t)}info(e,t){this.log("info",e,t)}warn(e,t){this.log("warn",e,t)}error(e,t){this.log("error",e,t)}verbose(e,t){this.log("verbose",e,t)}}t.AsyncQueueSingleton=o,o.instances=new Map},896:e=>{e.exports=require("fs")},928:e=>{e.exports=require("path")}},t={};function r(s){var n=t[s];if(void 0!==n)return n.exports;var i=t[s]={exports:{}};return e[s].call(i.exports,i,i.exports,r),i.exports}r.c=t;var s=r(r.s=435);module.exports=s})();
|
|
1
|
+
(()=>{"use strict";var e={171:e=>{e.exports=require("winston-daily-rotate-file")},298:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getFormattedDate=function(e=!1){const t=new Date,r=t.getFullYear(),s=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0");return e?`${r}-${s}-${n} ${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}:${String(t.getSeconds()).padStart(2,"0")}`:`${r}-${s}-${n}`},t.getMainDirectory=function(){const e=r(928);return r.c[r.s]?e.dirname(r.c[r.s].filename):process.cwd()}},306:e=>{e.exports=require("winston")},330:e=>{e.exports=JSON.parse('{"name":"proxy-pool-manager","version":"1.0.11","description":"proxy manager","main":"./dist/index.cjs","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"import":"./dist/index.mjs","require":"./dist/index.cjs","types":"./dist/index.d.ts"}},"files":["dist","package.json"],"scripts":{"build":"webpack --mode=production && tsc --emitDeclarationOnly --outDir dist && node scripts/generate-esm-wrapper.js","dev":"webpack --mode=development","watch":"webpack --watch --mode=development","build:analyze":"webpack --mode=production --analyze","prepublishOnly":"npm run build"},"author":"memeak","license":"ISC","devDependencies":{"@types/node":"^22.5.4","@webpack-cli/generators":"^3.0.7","clean-webpack-plugin":"^4.0.0","ts-loader":"^9.5.1","typescript":"^5.6.2","webpack":"^5.94.0","webpack-cli":"^5.1.4"},"dependencies":{"async":"^3.2.6","node-fetch":"^2.7.0","winston":"^3.18.3","winston-daily-rotate-file":"^5.0.0"},"packageManager":"pnpm@10.18.2+sha512.9fb969fa749b3ade6035e0f109f0b8a60b5d08a1a87fdf72e337da90dcc93336e2280ca4e44f2358a649b83c17959e9993e777c2080879f3801e6f0d999ad3dd"}')},378:function(e,t,r){var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.Request=void 0;const n=s(r(867)),i=r(388);class o{constructor(e={}){if(this.proxyManager=null,this.hasProxyManager=!1,void 0!==e.maxRetries&&(e.maxRetries<0||!Number.isInteger(e.maxRetries)))throw new Error("maxRetries 必须是非负整数");if(void 0!==e.timeout&&e.timeout<=0)throw new Error("timeout 必须是正数");if(void 0!==e.retryDelay&&e.retryDelay<0)throw new Error("retryDelay 必须是非负数");if(void 0!==e.retryDelayBase&&e.retryDelayBase<=0)throw new Error("retryDelayBase 必须是正数");if(void 0!==e.retryDelayMultiplier&&e.retryDelayMultiplier<=0)throw new Error("retryDelayMultiplier 必须是正数");this.maxRetries=e.maxRetries??3,this.timeout=e.timeout??30,this.logLevel=e.logLevel||"none",this.proxyStrategy=e.proxyStrategy||"sequential",this.retryDelay=e.retryDelay??null,this.retryDelayBase=e.retryDelayBase??1e3,this.retryDelayMultiplier=e.retryDelayMultiplier??2,this.rotateOnError=!0===e.rotateOnError;try{const t=e.instanceId||"default";this.proxyManager=i.ServiceLocator.get(`ProxyManager-${t}`),this.hasProxyManager=!0,this.log("info","成功获取 ProxyManager 实例",{instanceId:t})}catch(t){this.hasProxyManager=!1,this.log("info","ProxyManager 未初始化,将以轻量级模式运行(不使用代理管理功能)",{instanceId:e.instanceId||"default"})}}setLogLevel(e){try{i.ServiceLocator.get("DebugManager").setLogLevel(e),this.log("info",`设置日志等级: ${e}`)}catch(e){console.warn("DebugManager未注册,无法设置日志等级")}}getLogLevel(){try{return i.ServiceLocator.get("DebugManager").getLogLevel()}catch(e){return"info"}}log(e,t,r){try{const s=i.ServiceLocator.get("DebugManager");e.toUpperCase(),s.log(e,`[Request] ${t}`,r)}catch(s){const n=`[${e.toUpperCase()}]`;("error"===e?console.error:"warn"===e?console.warn:"debug"===e||"verbose"===e?console.debug:console.info)(`${n} [Request] ${t}`,r||"")}}async selectProxy(e){if(!0===e.options.noProxy)return this.log("info","noProxy 为 true,强制直连",{}),null;if(e.options.proxy){const t=e.options.proxy;return this.hasProxyManager&&this.proxyManager&&await this.proxyManager.addProxy(t).catch(()=>{}),this.log("info","使用请求级别代理",{proxy:t}),t}if(!this.hasProxyManager||!this.proxyManager)return null;const t=this.proxyManager.getProxiesCount();if(0===t)return null;const r=this.proxyManager.getAvailableProxy();return r&&this.log("info","使用策略选择代理",{proxy:r,strategy:this.proxyManager.getProxyStrategy(),index:this.proxyManager.getCurrentProxyIndex()+1,total:t}),r}async executeSingleRequest(e,t,r){const s=e.options.timeout||this.timeout,i=1e3*s;let o=null;try{o=r?r.proxy:await this.selectProxy(e);const a={method:e.method,headers:{},signal:AbortSignal.timeout(i)},c=e.options?{...e.options}:{};o&&(c.proxy=o),Object.keys(c).length>0&&(a.body=JSON.stringify(c),a.headers["Content-Type"]="application/json"),this.log("info",`开始请求 ${e.url} (尝试 ${t}/${this.maxRetries})`,{method:e.method,timeout:s,hasProxy:!!o});const l=Date.now(),u=await(0,n.default)(e.url,a),h=Date.now()-l;if(!u.ok)throw new Error(`HTTP Error: ${u.status} ${u.statusText}`);const g=await u.text();let y;try{y=JSON.parse(g)}catch{y=g}const d={status_code:u.status,success:u.ok,headers:Object.fromEntries(u.headers.entries()),data:y,error:u.ok?void 0:g,timestamp:(new Date).toISOString()};return this.hasProxyManager&&this.proxyManager&&o&&await this.proxyManager.recordProxyUsage(o,d.success,h).catch(()=>{}),{result:d,proxyUsed:o}}catch(r){if("TimeoutError"===r.name||"AbortError"===r.name){this.log("warn",`请求超时 (${s}s)`,{url:e.url,attempt:t});const r=new Error(`请求超时: ${s}秒`);throw r.proxyUsed=o,r.gatewayUnreachable=!0,r}throw r.proxyUsed=o,r.gatewayUnreachable=a(r),r}}isValidStatusCode(e){return e>=200&&e<300}async get(e,t={}){let r=e;return t.params&&Object.keys(t.params).length>0&&(r=`${e}?${new URLSearchParams(t.params).toString()}`),this.request({url:r,method:"GET",options:t})}async post(e,t={}){return this.request({url:e,method:"POST",options:t})}async put(e,t={}){return this.request({url:e,method:"PUT",options:t})}async delete(e,t={}){return this.request({url:e,method:"DELETE",options:t})}async patch(e,t={}){return this.request({url:e,method:"PATCH",options:t})}async request(e){const t={url:e.url,method:e.method,options:{...e.options,timeout:e.options.timeout||this.timeout}};let r=null;for(let e=1;e<=this.maxRetries;e++)try{const{result:s,proxyUsed:n}=await this.executeSingleRequest(t,e,r);r||(r={proxy:n});const i={status:s.status_code,statusText:this.getStatusText(s.status_code),headers:s.headers||{},error:s.error?String(s.error):null,errors:[],data:s.data,text:()=>"string"==typeof s.data?s.data:JSON.stringify(s.data),json:()=>s.data,buffer:()=>Buffer.from("string"==typeof s.data?s.data:JSON.stringify(s.data||{}))};if(this.shouldSwitchCredential(t,n,s.data)&&e<this.maxRetries){this.noteCredentialFailure(n),r=null,await this.waitBeforeRetry(e);continue}return this.log("info","请求成功",{url:t.url,status:i.status,attempt:e}),i}catch(s){r||(r={proxy:s.proxyUsed??null});const n=s.message;this.log("error","请求失败",{attempt:e,maxRetries:this.maxRetries,url:t.url,error:n});const i=!0===s.gatewayUnreachable||a(s);i&&this.log("warn",`网关不可达,尝试 ${e}/${this.maxRetries}`),this.rotateOnError&&!i&&!t.options.noProxy&&!t.options.proxy&&r.proxy&&this.hasProxyManager&&this.proxyManager?.shouldRotateProxy(s)&&e<this.maxRetries&&(this.noteCredentialFailure(r.proxy),r=null),e<this.maxRetries&&await this.waitBeforeRetry(e)}throw new Error(`${e.options.url} 请求失败,已尝试 ${this.maxRetries} 次都失败了`)}getStatusText(e){return{200:"OK",201:"Created",202:"Accepted",204:"No Content",400:"Bad Request",401:"Unauthorized",403:"Forbidden",404:"Not Found",500:"Internal Server Error",502:"Bad Gateway",503:"Service Unavailable"}[e]||`Status ${e}`}getCurrentProxy(){return this.hasProxyManager&&this.proxyManager?this.proxyManager.getCurrentProxy():null}async rotateProxy(){if(!this.hasProxyManager||!this.proxyManager)throw new Error("ProxyManager 未初始化,无法轮换代理");return await this.proxyManager.rotateProxy()}resetProxyUsage(){this.hasProxyManager&&this.proxyManager&&this.proxyManager.resetProxyUsage()}setProxyStrategy(e){if(!this.hasProxyManager||!this.proxyManager)throw new Error("ProxyManager 未初始化,无法设置代理策略");this.proxyManager.setProxyStrategy(e)}async checkProxy(e){if(!this.hasProxyManager||!this.proxyManager)throw new Error("ProxyManager 未初始化,无法检查代理");return this.proxyManager.checkProxy(e)}getAvailableProxiesList(){return this.hasProxyManager&&this.proxyManager?this.proxyManager.getAvailableProxiesList():[]}hasProxyManagement(){return this.hasProxyManager}shouldSwitchCredential(e,t,r){return!(!this.rotateOnError||!this.hasProxyManager)&&!e.options.noProxy&&!e.options.proxy&&!!t&&function(e){if(!e||"object"!=typeof e)return!1;const t=e,r=t.status_code,s=String(t.data&&"object"==typeof t.data?t.data.error??"":t.error??"").toLowerCase();return 407===r||(!!/(proxy|socks|tunnel|proxy authentication)/.test(s)||!(408!==r&&502!==r&&503!==r||!/(timed out|timeout|超时|connection refused|could not resolve|network is unreachable|econnrefused|etimedout)/.test(s)))}(r)}noteCredentialFailure(e){e&&this.proxyManager?.markProxyFailure&&(this.proxyManager.markProxyFailure(e),this.log("warn","上游代理失败,下次重试切换",{proxy:e}))}async waitBeforeRetry(e){let t;null!==this.retryDelay?(t=this.retryDelay,this.log("info",`等待 ${t}ms 后重试(固定间隔)`)):(t=this.retryDelayBase*Math.pow(this.retryDelayMultiplier,e-1),this.log("info",`等待 ${t}ms 后重试(指数退避:基础 ${this.retryDelayBase}ms,倍数 ${this.retryDelayMultiplier})`)),await new Promise(e=>setTimeout(e,t))}}function a(e){const t=[e?.message,e?.code,e?.cause?.message,e?.cause?.code].filter(Boolean).join(" ").toLowerCase();return t.includes("请求超时")||t.includes("econnrefused")||t.includes("enotfound")||t.includes("eai_again")||t.includes("etimedout")||t.includes("econnreset")||t.includes("ehostunreach")||t.includes("fetch failed")||t.includes("socket hang up")}t.Request=o,t.default=o},388:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ServiceLocator=void 0;class r{static shouldLog(e){try{if(this.services.has("DebugManager")){const t=this.services.get("DebugManager");if(t&&"function"==typeof t.getLogLevel){const r=t.getLogLevel(),s={none:0,error:1,warn:2,info:3,debug:4,verbose:5},n=s[r]||0;return(s[e]||0)<=n}}}catch(e){}return"error"===e||"warn"===e}static shouldLogForService(e,t){if(["DebugManager","AsyncQueue"].includes(e)&&("debug"===t||"verbose"===t)){try{if(this.services.has("DebugManager")){const e=this.services.get("DebugManager");if(e&&"function"==typeof e.getLogLevel)return"verbose"===e.getLogLevel()}}catch(e){}return!1}return this.shouldLog(t)}static get(e){if(this.services.has(e)){const t=this.services.get(e);return this.shouldLogForService(e,"debug")&&this.log("debug",`返回已注册的服务实例: ${e}`,{serviceType:this.getServiceType(t)}),t}if(this.dependencies.has(e)){this.shouldLogForService(e,"debug")&&this.log("debug",`通过工厂创建服务: ${e}`);const t=this.dependencies.get(e)();return this.services.set(e,t),this.shouldLogForService(e,"debug")&&this.log("debug",`工厂创建服务完成: ${e}`,{serviceType:this.getServiceType(t)}),t}const t=new Error(`[ServiceLocator] 服务未注册: ${e}`);throw this.log("error","服务未注册",{serviceName:e,availableServices:this.getAvailableServiceNames(),error:t.message}),t}static has(e){const t=this.services.has(e)||this.dependencies.has(e);return this.shouldLogForService(e,"debug")&&this.log("debug",`检查服务存在性: ${e}`,{exists:t,hasInstance:this.services.has(e),hasFactory:this.dependencies.has(e)}),t}static register(e,t){this.services.set(e,t),this.shouldLogForService(e,"info")&&this.log("info",`注册服务: ${e}`,{serviceType:this.getServiceType(t),hasFactory:this.dependencies.has(e)})}static registerFactory(e,t){this.dependencies.set(e,t),this.shouldLogForService(e,"info")&&this.log("info",`注册服务工厂: ${e}`,{hasExistingInstance:this.services.has(e)})}static log(e,t,r){if(!this.shouldLog(e))return;try{if(this.services.has("DebugManager")){const s=this.services.get("DebugManager");if(s&&"function"==typeof s.log)return e.toUpperCase(),void s.log(e,`[ServiceLocator] ${t}`,r)}}catch(e){}const s=`[${e.toUpperCase()}]`;("error"===e?console.error:"warn"===e?console.warn:"debug"===e||"verbose"===e?console.debug:console.info)(`${s} [ServiceLocator] ${t}`,r||"")}static getAvailableServiceNames(){const e=Array.from(this.services.keys()),t=Array.from(this.dependencies.keys()),r=[...new Set([...e,...t])];return this.shouldLog("debug")&&this.log("debug","获取可用服务名称",{total:r.length,services:e,factories:t}),r}static getStats(){const e=Array.from(this.services.keys()),t=Array.from(this.dependencies.keys()),r={totalServices:e.length,totalFactories:t.length,serviceNames:e,factoryNames:t};return this.shouldLog("debug")&&this.log("debug","服务统计",r),r}static isInitialized(){const e=this.has("DebugManager");return this.shouldLog("debug")&&this.log("debug","检查服务定位器初始化状态",{hasDebugManager:e,totalServices:this.services.size,totalFactories:this.dependencies.size}),e}static getServiceType(e){return e?e.constructor&&e.constructor.name?e.constructor.name:"function"==typeof e?"Function":Array.isArray(e)?"Array":"object"==typeof e?"Object":typeof e:"null"}static registerMultiple(e){const t=Object.keys(e);this.log("info","批量注册服务",{count:t.length,services:t}),Object.entries(e).forEach(([e,t])=>{this.register(e,t)})}static safeGet(e,t){try{return this.get(e)}catch(r){return this.log("warn",`安全获取服务失败: ${e}`,{error:r.message,usingDefault:void 0!==t}),t}}static reset(){this.services.clear(),this.dependencies.clear(),this.log("info","服务定位器已重置")}static initialize(){this.log("info","服务定位器初始化",{nodeEnv:"production"})}static clear(){const e=this.services.size,t=this.dependencies.size;this.services.clear(),this.dependencies.clear(),this.log("info","所有服务已清除",{clearedServices:e,clearedFactories:t})}static removeService(e){const t=this.services.has(e),r=this.dependencies.has(e);return this.services.delete(e),this.dependencies.delete(e),!(!t&&!r||(this.log("info",`移除服务: ${e}`,{hadService:t,hadFactory:r}),0))}static getExistingInstance(e){if(this.services.has(e))return this.services.get(e)}static hasOnlyFactory(e){return!this.services.has(e)&&this.dependencies.has(e)}static getCounts(){const e=this.services.size,t=this.dependencies.size,r=e+t;return this.shouldLog("debug")&&this.log("debug","服务数量统计",{instances:e,factories:t,total:r}),{instances:e,factories:t,total:r}}}t.ServiceLocator=r,r.services=new Map,r.dependencies=new Map},435:function(e,t,r){var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getMainDirectory=t.getFormattedDate=t.VERSION=t.ProxyRequestSDK=t.AsyncQueueSingleton=t.DebugManager=t.ServiceLocator=t.ProxyManager=t.Request=void 0,t.initializeServices=h,t.createProxyRequest=async function(e){return await h(e)},t.registerCoreServices=function(e={}){const t=e.instanceId||`core-${Date.now()}`,r=c.DebugManager.getInstance();e.logLevel&&r.setLogLevel(e.logLevel),a.ServiceLocator.register("DebugManager",r);const s=l.AsyncQueueSingleton.getInstance(t,{logLevel:e.logLevel});a.ServiceLocator.register(`AsyncQueue-${t}`,s);const n=o.ProxyManager.getInstance({proxies:e.proxies,proxy:e.proxy,logLevel:e.logLevel,instanceId:t});a.ServiceLocator.register(`ProxyManager-${t}`,n);const u=new i.Request({logLevel:e.logLevel,instanceId:t});a.ServiceLocator.register(`Request-${t}`,u)},t.registerRequestFactory=function(e,t){const r=t||`factory-${Date.now()}`;a.ServiceLocator.registerFactory(`Request-${r}`,e)},t.registerProxyManagerFactory=function(e,t){const r=t||`factory-${Date.now()}`;a.ServiceLocator.registerFactory(`ProxyManager-${r}`,e)},t.getStandaloneServices=function(e={}){const t=e.instanceId||`standalone-${Date.now()}`,r=l.AsyncQueueSingleton.getInstance(`standalone-${t}`,{logLevel:e.logLevel});return{proxyManager:o.ProxyManager.getInstance({proxies:e.proxies,proxy:e.proxy,logLevel:e.logLevel,instanceId:t}),request:new i.Request({logLevel:e.logLevel,instanceId:t}),asyncQueue:r}},t.cleanupServices=function(){a.ServiceLocator.clear(),l.AsyncQueueSingleton.destroyAllInstances(),o.ProxyManager.resetInstance()},t.checkServicesHealth=async function(e){try{const t=e||"default",r={DebugManager:a.ServiceLocator.has("DebugManager"),[`ProxyManager-${t}`]:a.ServiceLocator.has(`ProxyManager-${t}`),[`Request-${t}`]:a.ServiceLocator.has(`Request-${t}`),[`AsyncQueue-${t}`]:a.ServiceLocator.has(`AsyncQueue-${t}`)},s=l.AsyncQueueSingleton.getInstanceNames();return{proxyManager:a.ServiceLocator.has(`ProxyManager-${t}`),asyncQueues:s,services:r}}catch(e){return{proxyManager:!1,asyncQueues:[],services:{}}}};const n=s(r(330)),i=r(378);Object.defineProperty(t,"Request",{enumerable:!0,get:function(){return i.Request}});const o=r(696);Object.defineProperty(t,"ProxyManager",{enumerable:!0,get:function(){return o.ProxyManager}});const a=r(388);Object.defineProperty(t,"ServiceLocator",{enumerable:!0,get:function(){return a.ServiceLocator}});const c=r(577);Object.defineProperty(t,"DebugManager",{enumerable:!0,get:function(){return c.DebugManager}});const l=r(892);Object.defineProperty(t,"AsyncQueueSingleton",{enumerable:!0,get:function(){return l.AsyncQueueSingleton}});class u{constructor(e){this.proxyManagerInstance=null,this.isInitialized=!1,this.instanceId=e.instanceId||`sdk-${Date.now()}`,e.logLevel&&this.setLogLevel(e.logLevel);const t=!!(e.proxies&&e.proxies.length>0)||!!e.proxy;if((e.proxyCheckOptions||t)&&!t&&!e.proxyCheckOptions?.mainUrl&&!1!==e.proxyCheckEnabled)throw new Error("启用代理管理功能时,proxyCheckOptions.mainUrl 必须设置(除非 proxyCheckEnabled 为 false 或提供了代理数组)");if(!a.ServiceLocator.has("DebugManager")){const t=c.DebugManager.getInstance();e.logLevel&&t.setLogLevel(e.logLevel),a.ServiceLocator.register("DebugManager",t),this.log("info","注册 DebugManager")}if(!a.ServiceLocator.has(`AsyncQueue-${this.instanceId}`)){const t=l.AsyncQueueSingleton.getInstance(this.instanceId,{logLevel:e.logLevel});a.ServiceLocator.register(`AsyncQueue-${this.instanceId}`,t),this.log("info","注册 AsyncQueue",{instanceId:this.instanceId})}try{if(!a.ServiceLocator.has(`Request-${this.instanceId}`))throw new Error("Request 服务未注册。请使用 createProxyRequest() 或 initializeServices() 创建 SDK 实例,不要直接 new ProxyRequestSDK()。");this.requestInstance=a.ServiceLocator.get(`Request-${this.instanceId}`),a.ServiceLocator.has(`ProxyManager-${this.instanceId}`)?(this.proxyManagerInstance=a.ServiceLocator.get(`ProxyManager-${this.instanceId}`),this.log("info","使用已注册的服务实例(包含代理管理)",{instanceId:this.instanceId})):(this.proxyManagerInstance=null,this.log("info","使用已注册的服务实例(轻量级模式,无代理管理)",{instanceId:this.instanceId}))}catch(e){const t=e?.message||String(e);if(t.includes("请使用 createProxyRequest"))throw e;throw this.log("error","服务未正确初始化",{error:t}),new Error(`服务初始化失败: ${t}。请使用 createProxyRequest() 或 initializeServices() 创建实例。`)}this.initializeAsync(e).catch(e=>{console.error("SDK初始化失败:",e)})}log(e,t,r){try{const s=a.ServiceLocator.get("DebugManager");e.toUpperCase(),s.log(e,`[ProxyRequestSDK:${this.instanceId}] ${t}`,r)}catch(s){const n=`[${e.toUpperCase()}]`;("error"===e?console.error:"warn"===e?console.warn:"debug"===e?console.debug:console.info)(`${n} [ProxyRequestSDK:${this.instanceId}] ${t}`,r||"")}}async initializeAsync(e){try{this.proxyManagerInstance&&await this.proxyManagerInstance.waitForInitialization(),this.isInitialized=!0,this.log("info","初始化完成",{hasProxyManagement:!!this.proxyManagerInstance})}catch(e){throw this.log("error","初始化失败:",e),e}}async waitForReady(){for(;!this.isInitialized;)await new Promise(e=>setTimeout(e,100))}setLogLevel(e){try{a.ServiceLocator.get("DebugManager").setLogLevel(e),this.log("info",`设置日志等级: ${e}`)}catch(e){console.warn("DebugManager未注册,无法设置日志等级")}}getLogLevel(){try{return a.ServiceLocator.get("DebugManager").getLogLevel()}catch(e){return"info"}}getServiceInfo(){const e=["DebugManager",`ProxyManager-${this.instanceId}`,`Request-${this.instanceId}`,`AsyncQueue-${this.instanceId}`],t={};return e.forEach(e=>{t[e]=a.ServiceLocator.has(e)}),l.AsyncQueueSingleton.getInstanceNames().forEach(e=>{t[`AsyncQueue:${e}`]=!0}),t.hasProxyManagement=this.hasProxyManagement(),t}async get(e,t,r){await this.waitForReady();const s={...r,params:t?{...r?.params,...t}:r?.params};return this.requestInstance.get(e,s)}async post(e,t){return await this.waitForReady(),this.requestInstance.post(e,t)}async put(e,t){return await this.waitForReady(),this.requestInstance.put(e,t)}async delete(e,t){return await this.waitForReady(),this.requestInstance.delete(e,t)}async patch(e,t){return await this.waitForReady(),this.requestInstance.patch(e,t)}async request(e){return await this.waitForReady(),this.requestInstance.request({url:e.url,method:e.method||"GET",options:e.options||{}})}async addProxy(e){if(await this.waitForReady(),!this.proxyManagerInstance)throw new Error("代理管理功能未启用,请提供 proxies 或 proxyCheckOptions 来启用此功能");return this.proxyManagerInstance.addProxy(e)}async deleteProxy(e){if(await this.waitForReady(),!this.proxyManagerInstance)throw new Error("代理管理功能未启用,请提供 proxies 或 proxyCheckOptions 来启用此功能");return this.proxyManagerInstance.deleteProxy(e)}getAvailableProxies(){return this.proxyManagerInstance?this.proxyManagerInstance.getAvailableProxiesList():[]}getCurrentProxy(){return this.proxyManagerInstance?this.proxyManagerInstance.getCurrentProxy():null}async rotateProxy(){if(await this.waitForReady(),!this.proxyManagerInstance)throw new Error("代理管理功能未启用,请提供 proxies 或 proxyCheckOptions 来启用此功能");return this.proxyManagerInstance.rotateProxy()}setProxyStrategy(e){if(!this.proxyManagerInstance)throw new Error("代理管理功能未启用,请提供 proxies 或 proxyCheckOptions 来启用此功能");this.proxyManagerInstance.setProxyStrategy(e)}async checkProxy(e){if(await this.waitForReady(),!this.proxyManagerInstance)throw new Error("代理管理功能未启用,请提供 proxies 或 proxyCheckOptions 来启用此功能");return this.proxyManagerInstance.checkProxy(e)}async triggerProxyCheck(){if(await this.waitForReady(),!this.proxyManagerInstance)throw new Error("代理管理功能未启用,请提供 proxies 或 proxyCheckOptions 来启用此功能");return this.proxyManagerInstance.triggerProxyCheck()}hasProxyManagement(){return!!this.proxyManagerInstance}async getProxyStats(){if(await this.waitForReady(),!this.proxyManagerInstance)return{total:0,valid:0,invalid:0,available:0};const e=this.getAvailableProxies(),t=this.proxyManagerInstance?this.proxyManagerInstance.getProxiesCount():0;return{total:t,valid:e.length,invalid:t-e.length,available:e.length}}getProxyDetails(e){if(this.proxyManagerInstance)return this.proxyManagerInstance.getProxyDetails(e)}getQueueStats(){if(!this.proxyManagerInstance)throw new Error("代理管理功能未启用,无法获取队列统计");return this.proxyManagerInstance.getQueueStats()}getInstanceId(){return this.instanceId}async destroy(){this.log("info","开始清理资源"),[`ProxyManager-${this.instanceId}`,`Request-${this.instanceId}`,`AsyncQueue-${this.instanceId}`].forEach(e=>{a.ServiceLocator.has(e)&&(a.ServiceLocator.removeService(e),this.log("info",`清理服务: ${e}`))}),l.AsyncQueueSingleton.destroyInstance(this.instanceId),this.proxyManagerInstance&&(await this.proxyManagerInstance.destroy(),this.proxyManagerInstance=null),this.isInitialized=!1,this.log("info","资源清理完成")}}async function h(e){const t=e.instanceId||`instance-${Date.now()}`,r=!!(e.proxies&&e.proxies.length>0)||!!e.proxy,s=!(!e.proxyCheckOptions&&!r);if(s&&!r&&void 0===e.proxyCheckOptions?.mainUrl&&!1!==e.proxyCheckEnabled)throw new Error("启用代理管理功能时,proxyCheckOptions.mainUrl 必须设置(除非 proxyCheckEnabled 为 false 或提供了代理数组)");let n;[`ProxyManager-${t}`,`Request-${t}`,`AsyncQueue-${t}`].forEach(e=>{if(a.ServiceLocator.has(e)){if(e.startsWith("ProxyManager-"))try{const t=a.ServiceLocator.get(e);t&&"function"==typeof t.destroy&&t.destroy().catch(e=>{console.warn(`清理 ProxyManager 失败: ${e.message}`)})}catch(e){console.warn(`获取 ProxyManager 服务失败: ${e.message}`)}if(e.startsWith("AsyncQueue-")){const t=e.replace("AsyncQueue-","");l.AsyncQueueSingleton.destroyInstance(t)}a.ServiceLocator.removeService(e)}}),a.ServiceLocator.initialize(),a.ServiceLocator.has("DebugManager")?(n=a.ServiceLocator.get("DebugManager"),e.logLevel&&n.setLogLevel(e.logLevel)):(n=c.DebugManager.getInstance(),e.logLevel&&n.setLogLevel(e.logLevel),a.ServiceLocator.register("DebugManager",n));const h=`AsyncQueue-${t}`;let g;if(l.AsyncQueueSingleton.hasInstance(t)){if(g=l.AsyncQueueSingleton.getExistingInstance(t),g&&void 0!==e.logLevel)try{const t=a.ServiceLocator.get("DebugManager");e.logLevel&&t.setLogLevel(e.logLevel)}catch(e){console.warn("DebugManager未注册,无法更新debug状态")}}else g=l.AsyncQueueSingleton.getInstance(t,{logLevel:e.logLevel});a.ServiceLocator.register(h,g);let y=null;const d=`ProxyManager-${t}`;if(s)a.ServiceLocator.has(d)?(y=a.ServiceLocator.get(d),e.proxyStrategy&&y.setProxyStrategy(e.proxyStrategy),e.maxConcurrentChecks&&y.setMaxConcurrentChecks(e.maxConcurrentChecks)):y=o.ProxyManager.getInstance({proxies:e.proxies,proxy:e.proxy,proxyStrategy:e.proxyStrategy,maxConcurrentChecks:e.maxConcurrentChecks,logLevel:e.logLevel,proxyCheckOptions:e.proxyCheckOptions,proxyCheckEnabled:e.proxyCheckEnabled,instanceId:t}),await y.waitForInitialization(),a.ServiceLocator.register(d,y);else try{a.ServiceLocator.get("DebugManager").log("info","以轻量级模式运行(不使用代理管理功能)",{instanceId:t})}catch(e){console.info("以轻量级模式运行(不使用代理管理功能)",{instanceId:t})}const p=`Request-${t}`;let x;if(x=a.ServiceLocator.has(p)?a.ServiceLocator.get(p):new i.Request({maxRetries:e.maxRetries,timeout:e.timeout,logLevel:e.logLevel,retryDelay:e.retryDelay,retryDelayBase:e.retryDelayBase,retryDelayMultiplier:e.retryDelayMultiplier,rotateOnError:e.rotateOnError,instanceId:t}),a.ServiceLocator.register(p,x),e.logLevel&&"none"!==e.logLevel&&"error"!==e.logLevel)try{a.ServiceLocator.get("DebugManager").log("info","服务初始化完成",{instanceId:t,hasProxyManagement:s,proxyCount:y?y.getProxiesCount():0})}catch(e){console.info("服务初始化完成",{instanceId:t,hasProxyManagement:s,proxyCount:y?y.getProxiesCount():0})}return new u({...e,instanceId:t})}t.ProxyRequestSDK=u,t.default=u,t.VERSION=n.default.version;var g=r(298);Object.defineProperty(t,"getFormattedDate",{enumerable:!0,get:function(){return g.getFormattedDate}}),Object.defineProperty(t,"getMainDirectory",{enumerable:!0,get:function(){return g.getMainDirectory}})},577:function(e,t,r){var s,n=this&&this.__createBinding||(Object.create?function(e,t,r,s){void 0===s&&(s=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,s,n)}:function(e,t,r,s){void 0===s&&(s=r),e[s]=t[r]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||(s=function(e){return s=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},s(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=s(e),o=0;o<r.length;o++)"default"!==r[o]&&n(t,e,r[o]);return i(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.safeLog=t.debugManager=t.DebugManager=void 0;const a=o(r(896)),c=o(r(928)),l=o(r(306));r(171);class u{constructor(){this.logLevel="info",this.logLevelPriority={none:0,error:1,warn:2,info:3,debug:4,verbose:5},this.initializeLogger()}static getInstance(){return u.instance||(u.instance=new u),u.instance}initializeLogger(){const e=c.join(process.cwd(),"logs");a.existsSync(e)||a.mkdirSync(e,{recursive:!0});const t=l.format.combine(l.format.timestamp({format:"YYYY-MM-DD HH:mm:ss"}),l.format.printf(({timestamp:e,level:t,message:r,...s})=>{let n=`${e} [${t.toUpperCase()}] ${r}`;if(Object.keys(s).length>0){const{timestamp:e,level:t,message:r,...i}=s;if(Object.keys(i).length>0)try{n+=` | ${JSON.stringify(i)}`}catch{n+=` | ${String(i)}`}}return n}));this.logger=l.createLogger({level:this.getWinstonLevel(this.logLevel),format:t,transports:[new l.transports.Console({format:t}),new l.transports.DailyRotateFile({filename:c.join(e,"%DATE%.log"),format:t,datePattern:"YYYY/MM/DD",maxFiles:null})]})}getWinstonLevel(e){return{none:"error",error:"error",warn:"warn",info:"info",debug:"debug",verbose:"verbose"}[e]}setLogLevel(e){this.logLevel=e,this.logger.level=this.getWinstonLevel(e)}getLogLevel(){return this.logLevel}logInternal(e,t,r){const s=`[${e.toUpperCase()}]`;this.logger.log(this.getWinstonLevel(e),`${s} [DebugManager] ${t}`,r)}log(e,t,r){this.logger.log(this.getWinstonLevel(e),t,r)}error(e,t){this.log("error",e,t)}warn(e,t){this.log("warn",e,t)}info(e,t){this.log("info",e,t)}debug(e,t){this.log("debug",e,t)}verbose(e,t){this.log("verbose",e,t)}}t.DebugManager=u,t.debugManager=u.getInstance(),t.safeLog=t.debugManager.log.bind(t.debugManager)},626:e=>{e.exports=require("async")},696:function(e,t,r){var s,n=this&&this.__createBinding||(Object.create?function(e,t,r,s){void 0===s&&(s=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,s,n)}:function(e,t,r,s){void 0===s&&(s=r),e[s]=t[r]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||(s=function(e){return s=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},s(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=s(e),o=0;o<r.length;o++)"default"!==r[o]&&n(t,e,r[o]);return i(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.ProxyManager=void 0;const a=r(892),c=r(388);class l{constructor(e={}){this.lastSelectedUrl=null,this.isInitialized=!1,this.initializationPromise=null,this.instanceId=e.instanceId||`proxy-pool-manager-${Date.now()}`,this.logLevel=e.logLevel||"none",this.proxyCheckEnabled=e.proxyCheckEnabled??!0,this.proxyStrategy=e.proxyStrategy??"sequential",this.availableProxies=new Set,this.checkInProgress=new Set,this.maxConcurrentChecks=e.maxConcurrentChecks??5,this.asyncQueue=a.AsyncQueueSingleton.getInstance(this.instanceId,{concurrency:this.maxConcurrentChecks,autoStart:!0,logLevel:this.logLevel,onDrain:()=>{this.log("info","所有代理检测任务完成")},onError:e=>{this.log("error","代理检测任务出错:",e)},onSuccess:e=>{},taskHandler:async e=>(await new Promise(e=>setTimeout(e,1e3)),await this.taskHandler(e))}),this.proxies=[],Array.isArray(e.proxies)?e.proxies.forEach(e=>{this.addProxySync(e)}):e.proxy&&this.addProxySync(e.proxy),this.proxyCheckOptions={mainUrl:e.proxyCheckOptions?.mainUrl||"",testUrls:e.proxyCheckOptions?.testUrls??["http://httpbin.org/ip","http://api.ipify.org?format=json","http://ipinfo.io/json"],timeout:e.proxyCheckOptions?.timeout??5,successStatusCodes:e.proxyCheckOptions?.successStatusCodes??[200],checkInterval:e.proxyCheckOptions?.checkInterval??6e4,maxConsecutiveFails:e.proxyCheckOptions?.maxConsecutiveFails??3,maxResponseTime:e.proxyCheckOptions?.maxResponseTime??2e3},this.currentProxyIndex=0,this.usedProxies=new Set,this.initializationPromise=this.initializeAsync()}async initializeAsync(){try{this.isInitialized=!0,this.log("info",`ProxyManager初始化完成,加载了 ${this.proxies.length} 个代理`)}catch(e){throw this.log("error","ProxyManager初始化失败:",e),e}}async waitForInitialization(){if(!this.isInitialized){if(!this.initializationPromise)throw new Error("ProxyManager未正确初始化");await this.initializationPromise}}addProxySync(e){if(!this.proxies.find(t=>t.url===e)){const t={url:e,totalRequests:0,failCount:0,avgResponseTime:0,lastCheckTime:Date.now(),consecutiveFails:0,status:"valid"};this.proxies.push(t),this.availableProxies.add(e)}}static getInstance(e={}){const t=e.instanceId||`proxy-pool-manager-${Date.now()}`;if(l.instances.has(t))return l.instances.get(t);l.instanceLock=!0;try{if(l.instances.has(t))return l.instances.get(t);const r=new l({...e,instanceId:t});return l.instances.set(t,r),r}finally{l.instanceLock=!1}}static resetInstance(e){if(void 0!==e){const t=l.instances.get(e);t&&(t.destroy(),l.instances.delete(e))}else l.instances.forEach(e=>e.destroy()),l.instances.clear()}log(e,t,r){try{const s=c.ServiceLocator.get("DebugManager");e.toUpperCase(),s.log(e,`[ProxyManager] ${t}`,r)}catch(s){const n=`[${e.toUpperCase()}]`;("error"===e?console.error:"warn"===e?console.warn:"debug"===e||"verbose"===e?console.debug:console.info)(`${n} [ProxyManager] ${t}`,r||"")}}setLogLevel(e){try{c.ServiceLocator.get("DebugManager").setLogLevel(e),this.log("info",`设置日志等级: ${e}`)}catch(e){console.warn("DebugManager未注册,无法设置日志等级")}}getLogLevel(){try{return c.ServiceLocator.get("DebugManager").getLogLevel()}catch(e){return"info"}}async addProxy(e){if(!e?.trim())throw new Error("代理URL不能为空");await this.waitForInitialization();const t=this.proxies.find(t=>t.url===e);if(t)return this.log("info","代理已存在于内存中",{proxy:e}),t;const r={url:e,totalRequests:0,failCount:0,avgResponseTime:0,lastCheckTime:Date.now(),consecutiveFails:0,status:"valid"};return this.proxies.push(r),this.availableProxies.add(e),this.log("info","添加新代理",{proxy:e}),r}async deleteProxy(e){await this.waitForInitialization();const t=this.proxies.findIndex(t=>t.url===e);return-1!==t&&(this.proxies.splice(t,1),this.availableProxies.delete(e),this.log("info","从内存中删除代理",{proxy:e}),!0)}async deleteInvalidProxies(){await this.waitForInitialization();const e=this.proxies.filter(e=>"invalid"===e.status).length;return this.proxies=this.proxies.filter(e=>"valid"===e.status),this.availableProxies.clear(),this.proxies.forEach(e=>this.availableProxies.add(e.url)),this.log("info","从内存中删除无效代理",{count:e}),e}async standaloneProxyCheck(e,t,s,n){const{default:i}=await Promise.resolve().then(()=>o(r(867)));try{const r=new AbortController,o=setTimeout(()=>r.abort(),1e3*n),a={method:"POST",headers:{"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36"}};let c={url:s,method:"GET"};e&&(c.proxy=e,c.impersonate="chrome",c.timeout=n,a.body=JSON.stringify(c),a.headers["Content-Type"]="application/json");const l=await i(t,a),u=await l.text();let h;clearTimeout(o);try{h=JSON.parse(u)}catch{h=u}const g={status_code:l.status,success:l.ok,headers:Object.fromEntries(l.headers.entries()),data:h,error:l.ok?void 0:u,timestamp:(new Date).toISOString()},y=l.ok&&this.proxyCheckOptions.successStatusCodes.includes(g.status_code);return y?this.log("info","代理检测成功",{proxy:e,status:g.status_code,result:JSON.stringify(g.data)}):this.log("error","代理检测状态码不符",{proxy:e,statusCode:g.status_code,expected:this.proxyCheckOptions.successStatusCodes}),y}catch(t){return this.log("error","代理检测请求失败",{proxy:e,error:t.message}),!1}}async taskHandler(e){const t=Date.now();try{const r=this.proxyCheckOptions.testUrls[Math.floor(Math.random()*this.proxyCheckOptions.testUrls.length)],s=await this.standaloneProxyCheck(e.url,this.proxyCheckOptions.mainUrl,r,this.proxyCheckOptions.timeout),n=Date.now()-t;return e.totalRequests++,e.lastCheckTime=Date.now(),s?(e.avgResponseTime=(e.avgResponseTime*(e.totalRequests-1)+n)/e.totalRequests,e.consecutiveFails=0):(e.failCount++,e.consecutiveFails++),{proxy:e,isAvailable:s,responseTime:n}}catch(r){return this.log("error","代理检测出错",{proxy:e.url,error:r.message}),e.totalRequests++,e.failCount++,e.consecutiveFails++,e.lastCheckTime=Date.now(),{proxy:e,isAvailable:!1,responseTime:Date.now()-t}}}async checkAllProxies(){const e=this.proxies.filter(e=>"valid"===e.status);this.log("info",`开始批量检测代理,共 ${e.length} 个代理,最大并发数: ${this.maxConcurrentChecks}`),this.asyncQueue.updateConcurrency(this.maxConcurrentChecks);const t=[];try{const r=await this.asyncQueue.addBatch(e);t.push(...r),t.forEach(e=>{e.proxy.totalRequests>=2&&(e.proxy.failCount,e.proxy.totalRequests),e.proxy.failCount||e.proxy.avgResponseTime>this.proxyCheckOptions.maxResponseTime?(e.proxy.status="invalid",this.availableProxies.delete(e.proxy.url)):e.proxy.status="valid"});const s=e.filter(e=>"valid"===e.status).length,n=e.length-s;this.log("info","批量代理检测完成",{total:e.length,valid:s,invalid:n})}catch(e){this.log("error","批量代理检测失败",{error:e.message})}}getCurrentProxy(){return this.lastSelectedUrl?this.lastSelectedUrl:0===this.proxies.length?null:this.proxies[this.currentProxyIndex].url}markProxyFailure(e){const t=this.proxies.find(t=>t.url===e);t&&(t.failCount++,t.totalRequests++,t.consecutiveFails++,t.consecutiveFails>=this.proxyCheckOptions.maxConsecutiveFails&&(t.status="invalid",this.availableProxies.delete(t.url)))}selectProxy(){const e=this.proxies.filter(e=>"valid"===e.status);if(0===e.length)return this.proxies.length>0?(this.currentProxyIndex=0,this.proxies[0].url):null;let t;switch(this.proxyStrategy){case"sequential":t=this.currentProxyIndex%e.length,this.currentProxyIndex=(t+1)%e.length;break;case"random":this.usedProxies.size>=e.length&&this.usedProxies.clear();const r=Array.from({length:e.length},(e,t)=>t).filter(e=>!this.usedProxies.has(e));t=r.length>0?r[Math.floor(Math.random()*r.length)]:Math.floor(Math.random()*e.length),this.usedProxies.add(t),this.currentProxyIndex=t;break;case"failover":const s=[...e].sort((e,t)=>{if(e.consecutiveFails!==t.consecutiveFails)return e.consecutiveFails-t.consecutiveFails;const r=e.totalRequests>0?e.failCount/e.totalRequests:0,s=t.totalRequests>0?t.failCount/t.totalRequests:0;return r!==s?r-s:e.avgResponseTime-t.avgResponseTime});t=this.proxies.findIndex(e=>e.url===s[0].url),this.currentProxyIndex=t;break;default:t=this.currentProxyIndex%e.length}const r=e[t];return this.lastSelectedUrl=r.url,r.url}async rotateProxy(e){const t=e||this.lastSelectedUrl;t&&this.markProxyFailure(t);const r=this.proxies.filter(e=>"valid"===e.status);if(0===r.length)return this.proxies.length>0?(this.currentProxyIndex=0,this.lastSelectedUrl=this.proxies[0].url,this.log("info","无有效代理,默认使用第一个代理",{proxy:this.proxies[0].url}),this.proxies[0].url):null;let s=0;if(t){const e=this.proxies.findIndex(e=>e.url===t),n=this.proxies.find((t,r)=>r>e&&"valid"===t.status)||r[0],i=r.findIndex(e=>e.url===n.url);s=i>=0?i:0}this.currentProxyIndex=s;const n=r[s];return this.lastSelectedUrl=n.url,this.log("info","轮换代理",{from:t,to:n.url}),n.url}async recordProxyUsage(e,t,r){const s=this.proxies.find(t=>t.url===e);s&&(s.totalRequests++,t?(s.avgResponseTime=(s.avgResponseTime*(s.totalRequests-1)+r)/s.totalRequests,s.consecutiveFails=0):(s.failCount++,s.consecutiveFails++),s.lastCheckTime=Date.now(),t&&"invalid"===s.status&&(s.status="valid",this.availableProxies.add(s.url)))}resetProxyUsage(){this.usedProxies.clear(),this.log("info","重置代理使用记录")}setProxyStrategy(e){this.proxyStrategy=e,this.resetProxyUsage(),this.log("info","设置代理策略",{strategy:e})}async enhancedProxyCheck(e){if(!this.proxyCheckEnabled)return!0;if(this.checkInProgress.has(e))return!0;try{this.checkInProgress.add(e);const t=this.proxyCheckOptions.testUrls[Math.floor(Math.random()*this.proxyCheckOptions.testUrls.length)],r=Date.now(),s=await this.standaloneProxyCheck(e,this.proxyCheckOptions.mainUrl,t,this.proxyCheckOptions.timeout),n=Date.now()-r;return s&&n>this.proxyCheckOptions.maxResponseTime?(this.log("error","代理响应时间过长",{proxy:e,responseTime:n,threshold:this.proxyCheckOptions.maxResponseTime}),!1):s}catch(t){return this.log("error","代理检测异常",{proxy:e,error:t.message}),!1}finally{this.checkInProgress.delete(e)}}setMaxConcurrentChecks(e){e>0&&(this.maxConcurrentChecks=e,this.asyncQueue.updateConcurrency(e),this.log("info","更新最大并发检查数",{maxConcurrentChecks:e}))}getQueueStats(){return this.asyncQueue.stats}pauseProxyChecks(){this.asyncQueue.pause(),this.log("info","代理检测队列已暂停")}resumeProxyChecks(){this.asyncQueue.resume(),this.log("info","代理检测队列已恢复")}async checkProxy(e){const t=e||this.getCurrentProxy();if(!t)return!1;const r=await this.enhancedProxyCheck(t),s=this.proxies.find(e=>e.url===t);return s&&(s.status=r?"valid":"invalid",r?this.availableProxies.add(t):this.availableProxies.delete(t)),this.log("info","代理检查完成",{proxy:t,result:r}),r}getAvailableProxy(){const e=this.proxies.filter(e=>"valid"===e.status);if(0===e.length)return this.proxies.length>0?(this.currentProxyIndex=0,this.log("info","所有代理均不可用,默认使用第一个代理",{proxy:this.proxies[0].url}),this.proxies[0].url):null;const t=this.selectProxy();return this.log("info","获取代理",{proxy:t,strategy:this.proxyStrategy,available:e.length}),t}shouldRotateProxy(e){if(0===this.proxies.filter(e=>"valid"===e.status).length)return!1;if(!e||!e.message)return!1;const t=e.message.toLowerCase();return["proxy","socks","tunnel","connect","connection","timeout","超时","socket","网络","连接","etimedout","econnrefused"].some(e=>t.includes(e))}async triggerProxyCheck(){await this.waitForInitialization(),this.log("info","手动触发代理检测"),await this.checkAllProxies()}getAvailableProxiesList(){const e=this.proxies.filter(e=>"valid"===e.status).map(e=>e.url);return 0===e.length&&this.proxies.length>0?[this.proxies[0].url]:e}getProxyDetails(e){return this.proxies.find(t=>t.url===e)}getProxiesCount(){return this.proxies.length}getProxyStrategy(){return this.proxyStrategy}getCurrentProxyIndex(){return this.currentProxyIndex}async destroy(){if(this.checkInProgress.clear(),this.usedProxies.clear(),this.proxies=[],this.availableProxies.clear(),this.asyncQueue){const e=this.asyncQueue.getName();this.asyncQueue.pause(),a.AsyncQueueSingleton.destroyInstance(e)}this.isInitialized=!1,this.initializationPromise=null,l.instances.delete(this.instanceId),this.log("info","ProxyManager 已完全销毁")}}t.ProxyManager=l,l.instances=new Map,l.instanceLock=!1},867:e=>{e.exports=require("node-fetch")},892:function(e,t,r){var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.AsyncQueueSingleton=void 0;const n=s(r(626)),i=r(388);class o{constructor(e="default",t={}){this.queue=null,this.isInitialized=!1,this.logLevel="info",this.instanceName=e,this.logLevel=t.logLevel||"info",this.concurrency=t.concurrency||100,this.autoStart=!1!==t.autoStart,this.onDrain=t.onDrain||(()=>{this.log("info","所有任务完成")}),this.onError=t.onError||(e=>{this.log("error","任务错误:",e)}),this.onSuccess=t.onSuccess||(e=>{}),this.taskHandler=t.taskHandler||this.defaultTaskHandler,this.initializeQueue()}async defaultTaskHandler(e){return await new Promise(e=>setTimeout(e,1e3)),this.log("debug",`[${this.instanceName}] 剩余任务${this.queue?.length()} 运行任务数${this.queue?.running()}`),`运行成功 - ${this.instanceName}`}initializeQueue(){this.isInitialized||(this.queue=n.default.queue(async e=>await this.taskHandler(e),this.concurrency),this.queue.drain(()=>{this.onDrain()}),this.autoStart||this.queue.pause(),this.isInitialized=!0,this.log("info","队列初始化完成",{concurrency:this.concurrency,autoStart:this.autoStart}))}add(e,t=0){return new Promise((r,s)=>{if(!this.queue)return void s(new Error(`[${this.instanceName}] 队列未初始化`));const n=(t,n)=>{t?(this.log("error","任务执行失败",{task:e,error:t.message}),s(t)):(this.onSuccess(n),r(n))};t>0?this.queue.unshift(e,n):this.queue.push(e,n),this.log("debug","添加任务",{task:e,priority:t,queueLength:this.queue.length(),running:this.queue.running()})})}addBatch(e,t=0){return this.log("info","批量添加任务",{count:e.length,priority:t,instance:this.instanceName}),Promise.all(e.map(e=>this.add(e,t)))}updateConcurrency(e){if(e>0&&e!==this.concurrency&&this.queue){const t=this.concurrency;this.concurrency=e,this.queue.concurrency=e,this.log("info","更新并发数",{from:t,to:e,instance:this.instanceName})}}pause(){return this.queue?.pause(),this.log("info","队列暂停",{instance:this.instanceName}),this}resume(){return this.queue?.resume(),this.log("info","队列恢复",{instance:this.instanceName}),this}get length(){return this.queue?.length()||0}get running(){return this.queue?.running()||0}get workersList(){return this.queue?.workersList()||[]}get idle(){return this.queue?.idle()||!1}get stats(){return{length:this.length,running:this.running,concurrency:this.concurrency,idle:this.idle}}getName(){return this.instanceName}setTaskHandler(e){this.taskHandler=e,this.log("info","任务处理器已更新",{instance:this.instanceName})}destroy(){this.queue&&(this.queue.kill(),this.queue=null),this.isInitialized=!1,this.log("info","队列已销毁",{instance:this.instanceName})}log(e,t,r){try{const s=i.ServiceLocator.get("DebugManager");e.toUpperCase(),s.log(e,`[AsyncQueue:${this.instanceName}] ${t}`,r)}catch(s){const n=`[${e.toUpperCase()}]`;("error"===e?console.error:"warn"===e?console.warn:"debug"===e||"verbose"===e?console.debug:console.info)(`${n} [AsyncQueue:${this.instanceName}] ${t}`,r||"")}}setLogLevel(e){this.logLevel=e;try{i.ServiceLocator.get("DebugManager").setLogLevel(e)}catch(e){console.warn("DebugManager未注册,无法设置日志等级")}this.log("info",`设置日志等级: ${e}`)}getLogLevel(){return this.logLevel}static getInstance(e="default",t={}){if(o.instances.has(e)){const r=o.instances.get(e);if(r.isInitialized&&r.queue)return void 0!==t.logLevel&&t.logLevel!==r.logLevel&&r.setLogLevel(t.logLevel),t.concurrency&&t.concurrency!==r.concurrency&&r.updateConcurrency(t.concurrency),r;o.instances.delete(e)}const r=new o(e,t);return o.instances.set(e,r),r}static getInstanceNames(){return Array.from(o.instances.keys())}static getAllInstancesStats(){const e={};return o.instances.forEach((t,r)=>{e[r]=t.stats}),e}static destroyInstance(e="default"){if(o.instances.has(e)){const t=o.instances.get(e);t?.isInitialized&&t.queue&&t.destroy(),o.instances.delete(e),console.log(`[AsyncQueue] 已销毁实例: ${e}`)}}static destroyAllInstances(){const e=Array.from(o.instances.keys());e.forEach(e=>{o.destroyInstance(e)}),console.log(`[AsyncQueue] 已销毁所有实例: ${e.join(", ")}`)}static hasInstance(e="default"){return o.instances.has(e)}static getExistingInstance(e="default"){return o.instances.get(e)||null}debug(e,t){this.log("debug",e,t)}info(e,t){this.log("info",e,t)}warn(e,t){this.log("warn",e,t)}error(e,t){this.log("error",e,t)}verbose(e,t){this.log("verbose",e,t)}}t.AsyncQueueSingleton=o,o.instances=new Map},896:e=>{e.exports=require("fs")},928:e=>{e.exports=require("path")}},t={};function r(s){var n=t[s];if(void 0!==n)return n.exports;var i=t[s]={exports:{}};return e[s].call(i.exports,i,i.exports,r),i.exports}r.c=t;var s=r(r.s=435);module.exports=s})();
|
package/dist/index.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export declare class ProxyRequestSDK {
|
|
|
21
21
|
retryDelay?: number;
|
|
22
22
|
retryDelayBase?: number;
|
|
23
23
|
retryDelayMultiplier?: number;
|
|
24
|
+
rotateOnError?: boolean;
|
|
24
25
|
proxyCheckOptions?: {
|
|
25
26
|
mainUrl: string;
|
|
26
27
|
testUrls?: string[];
|
|
@@ -106,6 +107,7 @@ export declare function initializeServices(options: {
|
|
|
106
107
|
retryDelay?: number;
|
|
107
108
|
retryDelayBase?: number;
|
|
108
109
|
retryDelayMultiplier?: number;
|
|
110
|
+
rotateOnError?: boolean;
|
|
109
111
|
proxyCheckOptions?: {
|
|
110
112
|
mainUrl: string;
|
|
111
113
|
testUrls?: string[];
|
|
@@ -129,6 +131,7 @@ export declare function createProxyRequest(options: {
|
|
|
129
131
|
retryDelay?: number;
|
|
130
132
|
retryDelayBase?: number;
|
|
131
133
|
retryDelayMultiplier?: number;
|
|
134
|
+
rotateOnError?: boolean;
|
|
132
135
|
proxyCheckOptions?: {
|
|
133
136
|
mainUrl: string;
|
|
134
137
|
testUrls?: string[];
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"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CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CACX,GAAG,IAAI,CA+BZ;AAGD,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,OAAO,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAGxF;AAED,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,MAAM,YAAY,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAGlG;AAGD,wBAAgB,qBAAqB,CAAC,OAAO,GAAE;IAC7C,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CACX,GAAG;IACP,YAAY,EAAE,YAAY,CAAC;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,mBAAmB,CAAC;CACjC,CA2BA;AAGD,wBAAgB,eAAe,IAAI,IAAI,CAItC;AAGD,wBAAsB,mBAAmB,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IACtE,YAAY,EAAE,OAAO,CAAC;IACtB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC,CAAC,CAwBD;AAGD,eAAO,MAAM,OAAO,EAAE,MAAoB,CAAC;AAG3C,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/proxyManager.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare class ProxyManager {
|
|
|
5
5
|
private readonly instanceId;
|
|
6
6
|
private proxies;
|
|
7
7
|
private currentProxyIndex;
|
|
8
|
+
private lastSelectedUrl;
|
|
8
9
|
private proxyCheckEnabled;
|
|
9
10
|
private proxyStrategy;
|
|
10
11
|
private usedProxies;
|
|
@@ -66,6 +67,10 @@ export declare class ProxyManager {
|
|
|
66
67
|
* 获取当前代理
|
|
67
68
|
*/
|
|
68
69
|
getCurrentProxy(): string | null;
|
|
70
|
+
/**
|
|
71
|
+
* 把失败记在这次实际使用的代理上,不移动选择游标。
|
|
72
|
+
*/
|
|
73
|
+
markProxyFailure(proxyUrl: string): void;
|
|
69
74
|
/**
|
|
70
75
|
* 根据策略选择代理
|
|
71
76
|
*/
|
|
@@ -73,7 +78,7 @@ export declare class ProxyManager {
|
|
|
73
78
|
/**
|
|
74
79
|
* 轮换到下一个代理(失败时调用)
|
|
75
80
|
*/
|
|
76
|
-
rotateProxy(): Promise<string | null>;
|
|
81
|
+
rotateProxy(failedUrl?: string): Promise<string | null>;
|
|
77
82
|
/**
|
|
78
83
|
* 记录代理请求结果
|
|
79
84
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxyManager.d.ts","sourceRoot":"","sources":["../src/proxyManager.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,aAAa,EACb,SAAS,EAET,mBAAmB,EAEnB,QAAQ,EACT,MAAM,SAAS,CAAC;AASjB,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAC,SAAS,CAAwC;IAChE,OAAO,CAAC,MAAM,CAAC,YAAY,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,OAAO,CAAc;IAC7B,OAAO,CAAC,iBAAiB,CAAS;IAClC,OAAO,CAAC,iBAAiB,CAAU;IACnC,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,iBAAiB,CAA8B;IACvD,OAAO,CAAC,gBAAgB,CAAc;IACtC,OAAO,CAAC,eAAe,CAAc;IACrC,OAAO,CAAC,mBAAmB,CAAS;IACpC,OAAO,CAAC,UAAU,CAAsB;IACxC,OAAO,CAAC,aAAa,CAA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