Spaces:
Paused
Paused
github-actions[bot]
commited on
Commit
·
bce8f3a
1
Parent(s):
032ce5a
Update from GitHub Actions
Browse files- src/index.ts +19 -13
src/index.ts
CHANGED
|
@@ -232,25 +232,31 @@ app.get('/', async (c) => {
|
|
| 232 |
}
|
| 233 |
})
|
| 234 |
|
|
|
|
|
|
|
| 235 |
// 修改点 2: 添加 /genspark 路由来获取reCAPTCHA令牌
|
| 236 |
app.get('/genspark', async (c) => {
|
| 237 |
try {
|
| 238 |
const headers = Object.fromEntries(c.req.raw.headers)
|
| 239 |
// Get the cookie string from headers
|
| 240 |
const cookieString = headers.cookie || '';
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
|
| 255 |
// 执行脚本获取令牌
|
| 256 |
const token = await gensparkPage.evaluate(() => {
|
|
|
|
| 232 |
}
|
| 233 |
})
|
| 234 |
|
| 235 |
+
let lastCookies = null
|
| 236 |
+
|
| 237 |
// 修改点 2: 添加 /genspark 路由来获取reCAPTCHA令牌
|
| 238 |
app.get('/genspark', async (c) => {
|
| 239 |
try {
|
| 240 |
const headers = Object.fromEntries(c.req.raw.headers)
|
| 241 |
// Get the cookie string from headers
|
| 242 |
const cookieString = headers.cookie || '';
|
| 243 |
+
let gensparkPage = null
|
| 244 |
+
if (lastCookies != cookieString) {
|
| 245 |
+
// Parse cookies into an array of objects with name and value properties
|
| 246 |
+
const cookies = cookieString.split(';').map(cookie => {
|
| 247 |
+
const [name, value] = cookie.trim().split('=');
|
| 248 |
+
return { name, value, domain: 'www.genspark.ai', path: '/' };
|
| 249 |
+
}).filter(cookie => cookie.name && cookie.value);
|
| 250 |
+
gensparkPage = await initGensparkPage(cookies)
|
| 251 |
+
//刷新页面以确保获取新令牌
|
| 252 |
+
await gensparkPage.goto('https://www.genspark.ai/agents?type=moa_chat', {
|
| 253 |
+
waitUntil: 'networkidle',
|
| 254 |
+
timeout: 3600000
|
| 255 |
+
})
|
| 256 |
+
}
|
| 257 |
+
else {
|
| 258 |
+
gensparkPage = await initGensparkPage()
|
| 259 |
+
}
|
| 260 |
|
| 261 |
// 执行脚本获取令牌
|
| 262 |
const token = await gensparkPage.evaluate(() => {
|