Spaces:
Paused
Paused
Update index.js
Browse files
index.js
CHANGED
|
@@ -10,6 +10,7 @@ const Tokens = [];
|
|
| 10 |
let tokenManager;
|
| 11 |
let redisClient;
|
| 12 |
let currentIndex = 0;
|
|
|
|
| 13 |
const CONFIG = {
|
| 14 |
API: {
|
| 15 |
BASE_URL: "https://partyrock.aws",
|
|
@@ -95,8 +96,9 @@ class TokenManager {
|
|
| 95 |
}
|
| 96 |
|
| 97 |
async updateCacheTokens() {
|
|
|
|
| 98 |
CONFIG.DEFAULT_HEADERS["anti-csrftoken-a2z"] = Tokens[currentIndex].anti_csrftoken_a2z;
|
| 99 |
-
CONFIG.DEFAULT_HEADERS.Cookie = `idToken=${Tokens[currentIndex].idToken}; pr_refresh_token=${Tokens[currentIndex].pr_refresh_token};aws-waf-token=${Tokens[currentIndex].aws_waf_token}`;
|
| 100 |
CONFIG.DEFAULT_HEADERS.referer = Tokens[currentIndex].refreshUrl;
|
| 101 |
}
|
| 102 |
|
|
@@ -108,7 +110,6 @@ class TokenManager {
|
|
| 108 |
Tokens[currentIndex].aws_waf_token = wafToken;
|
| 109 |
await this.updateCacheTokens();
|
| 110 |
console.log("更新后的token",JSON.stringify(Tokens[currentIndex],null,2));
|
| 111 |
-
console.log("更新后cookie",CONFIG.DEFAULT_HEADERS.Cookie);
|
| 112 |
this.updateRedisTokens();
|
| 113 |
console.log("更新成功",)
|
| 114 |
return;
|
|
@@ -138,7 +139,7 @@ class TokenManager {
|
|
| 138 |
class Utils {
|
| 139 |
static async extractWaf() {
|
| 140 |
const browser = await puppeteer.launch({
|
| 141 |
-
headless:
|
| 142 |
args: [
|
| 143 |
'--no-sandbox',
|
| 144 |
'--disable-setuid-sandbox',
|
|
@@ -150,11 +151,22 @@ class Utils {
|
|
| 150 |
try {
|
| 151 |
const page = await browser.newPage();
|
| 152 |
await page.setExtraHTTPHeaders({
|
| 153 |
-
cookie: `pr_refresh_token=${Tokens[currentIndex].pr_refresh_token};idToken=${Tokens[currentIndex].idToken}`
|
| 154 |
});
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
// 直接从页面 cookies 中提取 aws-waf-token
|
| 159 |
const awsWafToken = (await page.cookies()).find(
|
| 160 |
cookie => cookie.name.toLowerCase() === 'aws-waf-token'
|
|
@@ -236,7 +248,8 @@ async function initializeService() {
|
|
| 236 |
anti_csrftoken_a2z: parsedRedis.anti_csrftoken_a2z,
|
| 237 |
pr_refresh_token: parsedRedis.pr_refresh_token,
|
| 238 |
aws_waf_token: parsedRedis.aws_waf_token,
|
| 239 |
-
idToken: parsedRedis.idToken
|
|
|
|
| 240 |
});
|
| 241 |
console.log(`成功添加第 ${index} 组 Token`);
|
| 242 |
} catch (error) {
|
|
@@ -259,13 +272,16 @@ async function initializeService() {
|
|
| 259 |
anti_csrftoken_a2z,
|
| 260 |
pr_refresh_token: cookies["pr_refresh_token"],
|
| 261 |
aws_waf_token: cookies["aws-waf-token"],
|
| 262 |
-
idToken: cookies["idToken"]
|
|
|
|
| 263 |
});
|
| 264 |
}
|
| 265 |
}
|
| 266 |
index++;
|
| 267 |
}
|
| 268 |
console.log('服务初始化完毕');
|
|
|
|
|
|
|
| 269 |
}
|
| 270 |
|
| 271 |
await initializeService();
|
|
@@ -515,9 +531,7 @@ app.post('/hf/v1/chat/completions', async (req, res) => {
|
|
| 515 |
...CONFIG.DEFAULT_HEADERS
|
| 516 |
},
|
| 517 |
body: JSON.stringify(requestPayload)
|
| 518 |
-
});
|
| 519 |
-
console.log("请求的头部",JSON.stringify(CONFIG.DEFAULT_HEADERS,null,2));
|
| 520 |
-
|
| 521 |
reqStatus = response.status;
|
| 522 |
switch (reqStatus) {
|
| 523 |
case 200:
|
|
|
|
| 10 |
let tokenManager;
|
| 11 |
let redisClient;
|
| 12 |
let currentIndex = 0;
|
| 13 |
+
let sessionId = null;
|
| 14 |
const CONFIG = {
|
| 15 |
API: {
|
| 16 |
BASE_URL: "https://partyrock.aws",
|
|
|
|
| 96 |
}
|
| 97 |
|
| 98 |
async updateCacheTokens() {
|
| 99 |
+
sessionId = Utils.uuidv4();
|
| 100 |
CONFIG.DEFAULT_HEADERS["anti-csrftoken-a2z"] = Tokens[currentIndex].anti_csrftoken_a2z;
|
| 101 |
+
CONFIG.DEFAULT_HEADERS.Cookie = `idToken=${Tokens[currentIndex].idToken}; pr_refresh_token=${Tokens[currentIndex].pr_refresh_token};aws-waf-token=${Tokens[currentIndex].aws_waf_token};cwr_s=${Tokens[currentIndex].cwr_s};cwr_u=${sessionId}`;
|
| 102 |
CONFIG.DEFAULT_HEADERS.referer = Tokens[currentIndex].refreshUrl;
|
| 103 |
}
|
| 104 |
|
|
|
|
| 110 |
Tokens[currentIndex].aws_waf_token = wafToken;
|
| 111 |
await this.updateCacheTokens();
|
| 112 |
console.log("更新后的token",JSON.stringify(Tokens[currentIndex],null,2));
|
|
|
|
| 113 |
this.updateRedisTokens();
|
| 114 |
console.log("更新成功",)
|
| 115 |
return;
|
|
|
|
| 139 |
class Utils {
|
| 140 |
static async extractWaf() {
|
| 141 |
const browser = await puppeteer.launch({
|
| 142 |
+
headless: false,
|
| 143 |
args: [
|
| 144 |
'--no-sandbox',
|
| 145 |
'--disable-setuid-sandbox',
|
|
|
|
| 151 |
try {
|
| 152 |
const page = await browser.newPage();
|
| 153 |
await page.setExtraHTTPHeaders({
|
| 154 |
+
cookie: `pr_refresh_token=${Tokens[currentIndex].pr_refresh_token};idToken=${Tokens[currentIndex].idToken};aws-waf-token=${Tokens[currentIndex].aws_waf_token};cwr_s=${Tokens[currentIndex].cwr_s};cwr_u=${Utils.uuidv4()}`
|
| 155 |
});
|
| 156 |
+
await page.setUserAgent(
|
| 157 |
+
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Safari/605.1.15"
|
| 158 |
+
)
|
| 159 |
+
await page.goto(Tokens[currentIndex].refreshUrl, {
|
| 160 |
+
waitUntil: 'networkidle2',
|
| 161 |
+
timeout: 30000
|
| 162 |
+
});
|
| 163 |
+
await page.evaluate(() => {
|
| 164 |
+
// 随机滚动
|
| 165 |
+
window.scrollBy(0, Math.random() * 500)
|
| 166 |
+
})
|
| 167 |
+
await page.evaluate(() => {
|
| 168 |
+
return new Promise(resolve => setTimeout(resolve, 2000))
|
| 169 |
+
})
|
| 170 |
// 直接从页面 cookies 中提取 aws-waf-token
|
| 171 |
const awsWafToken = (await page.cookies()).find(
|
| 172 |
cookie => cookie.name.toLowerCase() === 'aws-waf-token'
|
|
|
|
| 248 |
anti_csrftoken_a2z: parsedRedis.anti_csrftoken_a2z,
|
| 249 |
pr_refresh_token: parsedRedis.pr_refresh_token,
|
| 250 |
aws_waf_token: parsedRedis.aws_waf_token,
|
| 251 |
+
idToken: parsedRedis.idToken,
|
| 252 |
+
cwr_s: parsedRedis.cwr_s
|
| 253 |
});
|
| 254 |
console.log(`成功添加第 ${index} 组 Token`);
|
| 255 |
} catch (error) {
|
|
|
|
| 272 |
anti_csrftoken_a2z,
|
| 273 |
pr_refresh_token: cookies["pr_refresh_token"],
|
| 274 |
aws_waf_token: cookies["aws-waf-token"],
|
| 275 |
+
idToken: cookies["idToken"],
|
| 276 |
+
cwr_s: cookies["cwr_s"]
|
| 277 |
});
|
| 278 |
}
|
| 279 |
}
|
| 280 |
index++;
|
| 281 |
}
|
| 282 |
console.log('服务初始化完毕');
|
| 283 |
+
console.log(JSON.stringify(Tokens[0],null,2));
|
| 284 |
+
|
| 285 |
}
|
| 286 |
|
| 287 |
await initializeService();
|
|
|
|
| 531 |
...CONFIG.DEFAULT_HEADERS
|
| 532 |
},
|
| 533 |
body: JSON.stringify(requestPayload)
|
| 534 |
+
});
|
|
|
|
|
|
|
| 535 |
reqStatus = response.status;
|
| 536 |
switch (reqStatus) {
|
| 537 |
case 200:
|