Initial commit: svg backend

This commit is contained in:
adminko
2026-03-19 13:39:32 +03:00
commit 85fb2f4bb9
78 changed files with 6161 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
from defusedxml import ElementTree as DefusedET
from fastapi import HTTPException, status
from app.core.config import settings
def inspect_svg_bytes(content: bytes) -> int:
try:
root = DefusedET.fromstring(content)
except Exception as exc:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail=f"Invalid SVG XML: {exc.__class__.__name__}",
) from exc
tag = root.tag or ""
if not tag.endswith("svg"):
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="Root element is not <svg>",
)
element_count = sum(1 for _ in root.iter())
if element_count > settings.svg_max_elements:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="SVG element count exceeds configured limit",
)
return element_count