返回提交历史
Modified
g4f/api/__init__.py
+3
-3
XFEstudio/gpt4free
Refine API key requirement checks in Api class to simplify demo path handling
d497e70a
代码差异
1 个文件
+3
-3
@@ -478,7 +478,7 @@ class Api:
478
478
path.startswith("/v1/")
479
479
or (path.startswith("/api/") and path != "/api/logs")
480
480
or (path.startswith("/pa/") and not demo)
481
or (demo and path in ["/backend-api/v2/upload_cookies", "/api/logs"])
481
or (demo and path in ["/backend-api/v2/upload_cookies"])
482
482
)
483
483
484
484
@self.app.middleware("http")
@@ -536,11 +536,11 @@ class Api:
536
536
return ErrorResponse.from_message("G4F API key required", HTTP_401_UNAUTHORIZED)
537
537
if AppConfig.g4f_api_key is None and user is None:
538
538
return ErrorResponse.from_message("Invalid G4F API key", HTTP_403_FORBIDDEN)
539
elif not AppConfig.demo and not path.startswith("/images/") and not path.startswith("/media/"):
539
elif path == "/logs" or (not AppConfig.demo and not path.startswith("/images/") and not path.startswith("/media/")):
540
540
if user_g4f_api_key:
541
541
if user is None:
542
542
return ErrorResponse.from_message("Invalid G4F API key", HTTP_403_FORBIDDEN)
543
elif path.startswith("/backend-api/") or path.startswith("/chat/") or path.startswith("/playground/") or path in ["/logs", "/api/logs"]:
543
elif path.startswith("/backend-api/") or path.startswith("/chat/") or path.startswith("/playground/") or path in ["/logs"]:
544
544
try:
545
545
user = await self.get_username(request)
546
546
except HTTPException as e: