Skip to content

Commit fb52b37

Browse files
committed
refactor: reorganize imports and improve logging in middleware
1 parent fa1464b commit fb52b37

4 files changed

Lines changed: 9 additions & 5 deletions

File tree

app/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
from app.auth import ApiKeyMiddleware
1919
from app.config import settings
20-
from app.metrics import MetricsMiddleware, router as metrics_router
20+
from app.metrics import MetricsMiddleware
21+
from app.metrics import router as metrics_router
2122
from app.rate_limit import RateLimitMiddleware
2223
from app.routes import system_router, tts_router
2324
from app.tts_engine import tts_cache

app/auth.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,15 @@ async def dispatch(self, request: Request, call_next):
4747
if not provided:
4848
return JSONResponse(
4949
status_code=401,
50-
content={"error": "Missing API key", "detail": "Provide X-API-Key header or ?api_key= param"},
50+
content={
51+
"error": "Missing API key",
52+
"detail": "Provide X-API-Key header or ?api_key= param",
53+
},
5154
)
5255

5356
if not hmac.compare_digest(provided, self.api_key):
54-
log.warning(f"Invalid API key from {request.client.host if request.client else 'unknown'}")
57+
client_ip = request.client.host if request.client else "unknown"
58+
log.warning(f"Invalid API key from {client_ip}")
5559
return JSONResponse(
5660
status_code=403,
5761
content={"error": "Invalid API key"},

app/routes/system.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import edge_tts
77
from fastapi import APIRouter
88

9-
from app.config import settings
109
from app import tts_engine
10+
from app.config import settings
1111
from app.tts_engine import ensure_voices_loaded, stats, tts_cache
1212

1313
router = APIRouter(tags=["System"])

app/routes/tts.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""TTS API routes — POST /tts, POST /tts/stream, POST /tts/async."""
22
from __future__ import annotations
33

4-
import asyncio
54
import base64
65
import io
76
import json

0 commit comments

Comments
 (0)