XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

fix: Update cookie path in start-browser script for consistency across environments

ff66c45f
hlohaus <hlohaus@users.noreply.github.com>
提交于

代码差异

3 个文件 +13 -32
Modified g4f/Provider/needs_auth/LMArena.py +9 -29
@@ -244,7 +244,8 @@ class LMArena(AsyncGeneratorProvider, ProviderModelMixin, AuthFileMixin):
244 244 }
245 245 });
246 246 });""",
247 await_promise=True)
247 await_promise=True
248 )
248 249 if isinstance(captcha, str):
249 250 grecaptcha.append(captcha)
250 251 else:
@@ -276,7 +277,6 @@ class LMArena(AsyncGeneratorProvider, ProviderModelMixin, AuthFileMixin):
276 277 if isinstance(child, list) and len(data) >= 4:
277 278 pars_data(child[3])
278 279
279
280 280 def pars_data(data):
281 281 if not isinstance(data, (list, dict)):
282 282 return
@@ -306,7 +306,6 @@ class LMArena(AsyncGeneratorProvider, ProviderModelMixin, AuthFileMixin):
306 306 elif 'children' in json_data:
307 307 pars_children(json_data)
308 308
309
310 309 line_pattern = re.compile("^([0-9a-fA-F]+):(.*)")
311 310 pattern = r'self\.__next_f\.push\((\[[\s\S]*?\])\)(?=<\/script>)'
312 311 matches = re.findall(pattern, html)
@@ -324,8 +323,6 @@ class LMArena(AsyncGeneratorProvider, ProviderModelMixin, AuthFileMixin):
324 323 if "Evaluation" == data[2]:
325 324 js_files = dict(zip(data[1][::2], data[1][1::2]))
326 325 for js_id, js in list(js_files.items())[::-1]:
327 # if js_id != 5217:
328 # continue
329 326 js_url = f"{cls.url}/_next/{js}"
330 327 async with session.get(js_url) as js_response:
331 328 js_text = await js_response.text()
@@ -335,7 +332,6 @@ class LMArena(AsyncGeneratorProvider, ProviderModelMixin, AuthFileMixin):
335 332 for v, k in start_id:
336 333 cls._next_actions[k] = v
337 334 break
338
339 335 elif chunk_data.startswith(("[", "{")):
340 336 try:
341 337 data = json.loads(chunk_data)
@@ -350,9 +346,7 @@ class LMArena(AsyncGeneratorProvider, ProviderModelMixin, AuthFileMixin):
350 346 return files
351 347 url = "https://arena.ai/?chat-modality=image"
352 348 async with StreamSession(**args, ) as session:
353
354 349 for index, (_file, file_name) in enumerate(media):
355
356 350 data_bytes = to_bytes(_file)
357 351 # Check Cache
358 352 hasher = hashlib.md5()
@@ -366,19 +360,6 @@ class LMArena(AsyncGeneratorProvider, ProviderModelMixin, AuthFileMixin):
366 360
367 361 extension, file_type = detect_file_type(data_bytes)
368 362 file_name = file_name or f"file-{len(data_bytes)}{extension}"
369 # async with session.post(
370 # url="https://arena.ai/?chat-modality=image",
371 # json=[],
372 # headers={
373 # "accept": "text/x-component",
374 # "content-type": "text/plain;charset=UTF-8",
375 # "next-action": cls._next_actions["updateTouConsent"],
376 # "Referer": url
377 #
378 # }
379 # ) as response:
380 # await raise_for_status(response)
381
382 363 async with session.post(
383 364 url="https://arena.ai/?chat-modality=image",
384 365 json=[file_name, file_type],
@@ -386,8 +367,7 @@ class LMArena(AsyncGeneratorProvider, ProviderModelMixin, AuthFileMixin):
386 367 "accept": "text/x-component",
387 368 "content-type": "text/plain;charset=UTF-8",
388 369 "next-action": cls._next_actions["generateUploadUrl"],
389 "Referer": url
390
370 "referer": url
391 371 }
392 372 ) as response:
393 373 await raise_for_status(response)
@@ -404,11 +384,11 @@ class LMArena(AsyncGeneratorProvider, ProviderModelMixin, AuthFileMixin):
404 384 raise Exception("Failed to get upload URL")
405 385
406 386 async with session.put(
407 url=uploadUrl,
408 headers={
409 "content-type": file_type,
410 },
411 data=data_bytes,
387 url=uploadUrl,
388 headers={
389 "content-type": file_type,
390 },
391 data=data_bytes,
412 392 ) as response:
413 393 await raise_for_status(response)
414 394 async with session.post(
@@ -418,7 +398,7 @@ class LMArena(AsyncGeneratorProvider, ProviderModelMixin, AuthFileMixin):
418 398 "accept": "text/x-component",
419 399 "content-type": "text/plain;charset=UTF-8",
420 400 "next-action": cls._next_actions["getSignedUrl"],
421 "Referer": url
401 "referer": url
422 402 }
423 403 ) as response:
424 404 await raise_for_status(response)
Modified g4f/gui/server/backend_api.py +2 -1
@@ -358,7 +358,8 @@ class Backend_Api(Api):
358 358 @app.route('/backend-api/v2/version', methods=['GET'])
359 359 def version():
360 360 resp = jsonify(self.get_version())
361 resp.set_cookie('fingerprint', base64.b64encode(str(int(time.time())).encode()).decode(), max_age=60 * 60 *2, httponly=True, secure=True)
361 if not if request.args.get("cache"):
362 resp.set_cookie('fingerprint', base64.b64encode(str(int(time.time())).encode()).decode(), max_age=60 * 60 *2, httponly=True, secure=True)
362 363 return resp
363 364
364 365 @app.route('/backend-api/v2/create', methods=['GET'])
Modified scripts/start-browser.sh +2 -2
@@ -120,12 +120,12 @@ echo "Starting browser: $BROWSER_BIN"
120 120
121 121 if [[ "$BROWSER_BIN" == *.exe ]]; then
122 122 # Windows: launch once and exit — the browser manages its own lifecycle
123 rm -f ~/g4f/cookies/.browser_is_open
123 rm -f ~/.g4f/cookies/.browser_is_open
124 124 "$BROWSER_BIN" "${BROWSER_FLAGS[@]}"
125 125 else
126 126 # Linux: loop and relaunch if the browser exits
127 127 while true; do
128 rm -f ~/g4f/cookies/.browser_is_open
128 rm -f ~/.g4f/cookies/.browser_is_open
129 129 "$BROWSER_BIN" "${BROWSER_FLAGS[@]}"
130 130 sleep 5
131 131 done