|
@@ -62,7 +62,7 @@ class ProxyService {
|
|
}
|
|
}
|
|
|
|
|
|
// 添加重试机制
|
|
// 添加重试机制
|
|
- async proxyRequestWithRetry(options, maxRetries = 3, delay = 1000) {
|
|
|
|
|
|
+ async proxyRequestWithRetry(options, maxRetries = 3, delay = 3000) {
|
|
for (let i = 0; i < maxRetries; i++) {
|
|
for (let i = 0; i < maxRetries; i++) {
|
|
try {
|
|
try {
|
|
return await this.proxyRequest(options);
|
|
return await this.proxyRequest(options);
|
|
@@ -76,57 +76,4 @@ class ProxyService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-// 使用示例
|
|
|
|
-// async function example() {
|
|
|
|
-// const proxyService = new ProxyService();
|
|
|
|
-
|
|
|
|
-// try {
|
|
|
|
-// const result = await proxyService.proxyRequestWithRetry({
|
|
|
|
-// url: 'https://api.example.com/data',
|
|
|
|
-// method: 'post',
|
|
|
|
-// headers: {
|
|
|
|
-// 'Content-Type': 'application/json'
|
|
|
|
-// },
|
|
|
|
-// data: {
|
|
|
|
-// key: 'value'
|
|
|
|
-// }
|
|
|
|
-// });
|
|
|
|
-
|
|
|
|
-// console.log('Success:', result);
|
|
|
|
-// } catch (error) {
|
|
|
|
-// console.error('Final error:', error);
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
-// // 批量请求处理
|
|
|
|
-// class BatchProxyRequests {
|
|
|
|
-// constructor(proxyService) {
|
|
|
|
-// this.proxyService = proxyService;
|
|
|
|
-// this.queue = [];
|
|
|
|
-// this.concurrency = 3; // 并发数
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
-// addRequest(options) {
|
|
|
|
-// this.queue.push(options);
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
-// async processBatch() {
|
|
|
|
-// const results = [];
|
|
|
|
-
|
|
|
|
-// while (this.queue.length > 0) {
|
|
|
|
-// const batch = this.queue.splice(0, this.concurrency);
|
|
|
|
-// const promises = batch.map(options =>
|
|
|
|
-// this.proxyService.proxyRequestWithRetry(options)
|
|
|
|
-// .catch(error => ({ error }))
|
|
|
|
-// );
|
|
|
|
-
|
|
|
|
-// const batchResults = await Promise.all(promises);
|
|
|
|
-// results.push(...batchResults);
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
-// return results;
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
module.exports = ProxyService;
|
|
module.exports = ProxyService;
|