perf+security: fix build, secure downloads, dedupe translations, refactor i18n
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 2m49s

Frontend:
- Fix Framer Motion / motion-dom build error by pinning framer-motion to
  11.18.2 (compatible with React 19 and Next.js 16).
- Add cross-env and build:local script to bypass standalone symlink errors
  on Windows without Developer Mode.
- Allow NEXT_OUTPUT=default to disable standalone output for local builds.
- Refactor i18n: split 14,177-line src/lib/i18n.tsx into per-locale,
  per-namespace JSON files under src/lib/i18n/messages/.
- Load English synchronously; other locales loaded on demand via dynamic
  imports (reduces initial bundle, improves maintainability).
- Remove unused next-intl message files src/messages/en.json and fr.json.

Backend:
- Remove insecure legacy /api/v1/download/{filename} and /api/v1/cleanup/{filename}
  endpoints. The job-based /api/v1/download/{job_id} already enforces ownership.
- Deduplicate texts in TranslationService.translate_batch before sending them
  to the provider, reducing API calls for repeated strings.
- Pin httpx to <0.28 to fix TestClient incompatibility with starlette 0.35.1.
- Add pytest-cov and ruff dev dependencies/config.

DevOps:
- Remove hardcoded Grafana password from docker-compose.yml and
  docker-compose.monitoring.yml; use GRAFANA_PASSWORD env var.
- Change default TRANSLATION_SERVICE from ollama to google in
  docker-compose.yml (Ollama is an optional profile).
- Add GRAFANA_PASSWORD to .env.example.
- Add .coverage and frontend/pnpm-workspace.yaml to .gitignore.

Tests:
- Update API versioning tests for removed legacy endpoints.
- Add tests/test_translation_service.py for deduplication behavior.

Verified:
- pnpm run build:local passes.
- uv run pytest tests/test_providers/* tests/test_translation_service.py
  tests/test_story_3_5_api_versioning.py tests/test_download_endpoint.py
  tests/test_translators/test_excel_translator.py: provider/translator tests
  pass; one pre-existing French error-message test still fails (message is
  returned in English, unrelated to this change).
This commit is contained in:
2026-06-14 16:44:18 +02:00
parent eda6821632
commit fa637abff0
365 changed files with 23910 additions and 14955 deletions

View File

@@ -21,26 +21,6 @@ logger = logging.getLogger(__name__)
router = APIRouter(prefix="/api/v1", tags=["Legacy"])
def _safe_output_path(filename: str):
"""
Resolve filename to a path under config.OUTPUT_DIR. Prevents path traversal.
Returns (Path, True) if valid, (None, False) if invalid.
"""
if not filename or ".." in filename or "/" in filename or "\\" in filename:
return None, False
safe_name = Path(filename).name
if not safe_name.strip():
return None, False
base = config.OUTPUT_DIR.resolve()
try:
resolved = (config.OUTPUT_DIR / safe_name).resolve()
if not resolved.is_relative_to(base):
return None, False
return resolved, True
except (ValueError, OSError):
return None, False
def _resolve_model(
cfg_model: Optional[str],
model_env: str,
@@ -340,41 +320,6 @@ async def translate_batch_documents(
}
@router.get("/download/{filename}")
async def download_file(filename: str):
"""Download a translated file by filename. Filename is sanitized to prevent path traversal."""
file_path, ok = _safe_output_path(filename)
if not ok or file_path is None:
raise HTTPException(status_code=400, detail="Invalid filename")
if not file_path.exists():
raise HTTPException(status_code=404, detail="File not found")
return FileResponse(
path=file_path,
filename=file_path.name,
media_type="application/octet-stream",
)
@router.delete("/cleanup/{filename}")
async def cleanup_translated_file(filename: str):
"""Cleanup a translated file after download. Filename is sanitized to prevent path traversal."""
file_path, ok = _safe_output_path(filename)
if not ok or file_path is None:
raise HTTPException(status_code=400, detail="Invalid filename")
try:
if not file_path.exists():
raise HTTPException(status_code=404, detail="File not found")
file_handler.cleanup_file(file_path)
return {"message": f"File {file_path.name} deleted successfully"}
except HTTPException:
raise
except Exception as e:
logger.exception("Cleanup error")
raise HTTPException(
status_code=500, detail="Erreur lors de la suppression du fichier."
)
@router.post("/extract-texts")
async def extract_texts_from_document(
file: UploadFile = File(..., description="Document file to extract texts from"),