bobocup commited on
Commit
dcc5257
·
verified ·
1 Parent(s): 790c62f

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +12 -9
index.js CHANGED
@@ -105,18 +105,20 @@ class TokenManager {
105
 
106
  async updateTokens(response, isWaf = false) {
107
  if (isWaf) {
108
- var wafToken = await Utils.extractWaf();
109
  if (wafToken) {
 
110
  Tokens[currentIndex].aws_waf_token = wafToken;
 
 
111
  await this.updateCacheTokens();
112
- this.updateRedisTokens();
113
- currentIndex = (currentIndex + 1) % Tokens.length;
114
- console.log("成功提取 aws-waf-token");
115
- } else {
116
- currentIndex = (currentIndex + 1) % Tokens.length;
117
- await this.updateCacheTokens();
118
- console.log("提取aws-waf-token失败");
119
  }
 
120
  } else {
121
  const newCsrfToken = response.headers.get('anti-csrftoken-a2z');
122
  const cookies = response.headers.get('set-cookie');
@@ -130,8 +132,9 @@ class TokenManager {
130
  this.updateRedisTokens();//最后更新redis数据库缓存,异步
131
  console.log("更新缓存完毕");
132
  }
133
- currentIndex = (currentIndex + 1) % Tokens.length;
134
  }
 
 
135
  }
136
  }
137
 
 
105
 
106
  async updateTokens(response, isWaf = false) {
107
  if (isWaf) {
108
+ const wafToken = await Utils.extractWaf();
109
  if (wafToken) {
110
+ // 立即更新内存中的token
111
  Tokens[currentIndex].aws_waf_token = wafToken;
112
+
113
+ // 强制刷新请求头
114
  await this.updateCacheTokens();
115
+
116
+ // 持久化到Redis
117
+ await this.updateRedisTokens();
118
+
119
+ console.log("✅ 成功更新aws-waf-token | 新token长度:", wafToken.length);
 
 
120
  }
121
+ // 无论成功失败都保持当前索引(单账号场景无影响)
122
  } else {
123
  const newCsrfToken = response.headers.get('anti-csrftoken-a2z');
124
  const cookies = response.headers.get('set-cookie');
 
132
  this.updateRedisTokens();//最后更新redis数据库缓存,异步
133
  console.log("更新缓存完毕");
134
  }
 
135
  }
136
+ // 保持原有轮换逻辑(单账号场景无副作用)
137
+ currentIndex = (currentIndex + 1) % Tokens.length;
138
  }
139
  }
140