返回提交历史
Modified
g4f/api/__init__.py
+4
-4
XFEstudio/gpt4free
Update API log fetch to include credentials and refine API key path checks
23298d31
代码差异
1 个文件
+4
-4
@@ -213,7 +213,7 @@ function btag(e){if(e.streaming&&e.response_body==null)return\'<span class="tag
213
213
function esc(s){return String(s??\'\'). replace(/&/g,\'&\').replace(/</g,\'<\').replace(/>/g,\'>\');}
214
214
function fmt(v){if(v==null)return\'(empty)\';if(typeof v===\'object\')return JSON.stringify(v,null,2);return String(v);}
215
215
async function load(){
216
try{var r=await fetch(\'/api/logs?limit=500\');if(!r.ok)return;var d=await r.json();all=d.entries||[];render();}catch(e){}
216
try{var r=await fetch(\'/api/logs?limit=500\', { credentials: 'include' });if(!r.ok)return;var d=await r.json();all=d.entries||[];render();}catch(e){}
217
217
}
218
218
function render(){
219
219
var q=document.getElementById(\'q\').value.trim().toLowerCase();
@@ -478,9 +478,9 @@ class Api:
478
478
"""Return ``True`` when *path* must present a G4F API key."""
479
479
return (
480
480
path.startswith("/v1/")
481
or path.startswith("/api/")
481
or (path.startswith("/api/") and path != "/api/logs")
482
482
or (path.startswith("/pa/") and not demo)
483
or (demo and path in ["/backend-api/v2/upload_cookies", "/logs", "/api/logs"])
483
or (demo and path in ["/backend-api/v2/upload_cookies"])
484
484
)
485
485
486
486
@self.app.middleware("http")
@@ -542,7 +542,7 @@ class Api:
542
542
if user_g4f_api_key:
543
543
if user is None:
544
544
return ErrorResponse.from_message("Invalid G4F API key", HTTP_403_FORBIDDEN)
545
elif path.startswith("/backend-api/") or path.startswith("/chat/"):
545
elif path.startswith("/backend-api/") or path.startswith("/chat/") or path.startswith("/playground/") or path in ["/logs", "/api/logs"]:
546
546
try:
547
547
user = await self.get_username(request)
548
548
except HTTPException as e: