Spaces:
Sleeping
Sleeping
import fix
Browse files- app/__init__.py +1 -20
- app/api/factcheck_router.py +1 -1
- app/api/routes.py +1 -1
- app/dependencies.py +21 -0
app/__init__.py
CHANGED
|
@@ -1,7 +1,4 @@
|
|
| 1 |
-
import
|
| 2 |
-
|
| 3 |
-
from fastapi import FastAPI, HTTPException, Security, status
|
| 4 |
-
from fastapi.security import APIKeyHeader
|
| 5 |
from slowapi import _rate_limit_exceeded_handler
|
| 6 |
from slowapi.errors import RateLimitExceeded
|
| 7 |
from app.api.routes import router as api_router
|
|
@@ -16,22 +13,6 @@ app = FastAPI(
|
|
| 16 |
version="1.0.0",
|
| 17 |
)
|
| 18 |
|
| 19 |
-
API_KEY_NAME = "X-API-Key"
|
| 20 |
-
api_key_header = APIKeyHeader(name=API_KEY_NAME, auto_error=False)
|
| 21 |
-
EXPECTED_API_KEY = os.getenv("BACKEND_API_KEY")
|
| 22 |
-
|
| 23 |
-
async def verify_api_key(api_key: str = Security(api_key_header)):
|
| 24 |
-
if not EXPECTED_API_KEY:
|
| 25 |
-
raise HTTPException(
|
| 26 |
-
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
| 27 |
-
detail="Błąd serwera: Klucz API nie został skonfigurowany."
|
| 28 |
-
)
|
| 29 |
-
if api_key != EXPECTED_API_KEY:
|
| 30 |
-
raise HTTPException(
|
| 31 |
-
status_code=status.HTTP_401_UNAUTHORIZED,
|
| 32 |
-
detail="Brak autoryzacji: Nieprawidłowy lub brakujący klucz API."
|
| 33 |
-
)
|
| 34 |
-
return api_key
|
| 35 |
|
| 36 |
app.state.limiter = limiter
|
| 37 |
app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
|
|
|
|
|
|
|
|
|
| 2 |
from slowapi import _rate_limit_exceeded_handler
|
| 3 |
from slowapi.errors import RateLimitExceeded
|
| 4 |
from app.api.routes import router as api_router
|
|
|
|
| 13 |
version="1.0.0",
|
| 14 |
)
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
app.state.limiter = limiter
|
| 18 |
app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)
|
app/api/factcheck_router.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
from fastapi import APIRouter, Depends, HTTPException
|
| 2 |
-
from app import verify_api_key
|
| 3 |
from app.models.factcheck_schemas import FactCheckRequest, FactCheckResponse, FactCheckSource
|
| 4 |
from app.services.factcheck_service import analyze_with_gemini_grounding
|
| 5 |
|
|
|
|
| 1 |
from fastapi import APIRouter, Depends, HTTPException
|
| 2 |
+
from app.dependencies import verify_api_key
|
| 3 |
from app.models.factcheck_schemas import FactCheckRequest, FactCheckResponse, FactCheckSource
|
| 4 |
from app.services.factcheck_service import analyze_with_gemini_grounding
|
| 5 |
|
app/api/routes.py
CHANGED
|
@@ -2,7 +2,7 @@ import asyncio
|
|
| 2 |
from collections import defaultdict
|
| 3 |
import logging
|
| 4 |
from fastapi import APIRouter, Depends, HTTPException, Request, status
|
| 5 |
-
from app import verify_api_key
|
| 6 |
from app.services.queue import get_queue_service
|
| 7 |
from slowapi.errors import RateLimitExceeded
|
| 8 |
from limits import parse
|
|
|
|
| 2 |
from collections import defaultdict
|
| 3 |
import logging
|
| 4 |
from fastapi import APIRouter, Depends, HTTPException, Request, status
|
| 5 |
+
from app.dependencies import verify_api_key
|
| 6 |
from app.services.queue import get_queue_service
|
| 7 |
from slowapi.errors import RateLimitExceeded
|
| 8 |
from limits import parse
|
app/dependencies.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from fastapi import HTTPException, Security, status
|
| 3 |
+
from fastapi.security import APIKeyHeader
|
| 4 |
+
|
| 5 |
+
API_KEY_NAME = "X-API-Key"
|
| 6 |
+
api_key_header = APIKeyHeader(name=API_KEY_NAME, auto_error=False)
|
| 7 |
+
|
| 8 |
+
EXPECTED_API_KEY = os.getenv("BACKEND_API_KEY")
|
| 9 |
+
|
| 10 |
+
async def verify_api_key(api_key: str = Security(api_key_header)):
|
| 11 |
+
if not EXPECTED_API_KEY:
|
| 12 |
+
raise HTTPException(
|
| 13 |
+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
| 14 |
+
detail="Błąd serwera: Klucz API nie został skonfigurowany."
|
| 15 |
+
)
|
| 16 |
+
if api_key != EXPECTED_API_KEY:
|
| 17 |
+
raise HTTPException(
|
| 18 |
+
status_code=status.HTTP_401_UNAUTHORIZED,
|
| 19 |
+
detail="Brak autoryzacji: Nieprawidłowy lub brakujący klucz API."
|
| 20 |
+
)
|
| 21 |
+
return api_key
|