اضافه شدن قابلیت مقایسه شماتیک

This commit is contained in:
2026-11-07 15:42:53 +03:30
والد f5da7ee41b
کامیت d2b8ae96c9
28فایلهای تغییر یافته به همراه1012 افزوده شده و 33 حذف شده
+20
مشاهده پرونده
@@ -0,0 +1,20 @@
"""Shared bounded native schematic upload validation."""
from fastapi import HTTPException
from .config import settings
from .parser.record_decoder import ParseError,detect_format
async def read_schematic(file):
try:
name=(file.filename or '').replace('\\','/').rsplit('/',1)[-1]
name=''.join(c for c in name if c.isprintable())[:255]
if not name.lower().endswith('.schdoc'):
raise HTTPException(415,{'code':'unsupported_file_type','message':'Upload a .SchDoc file'})
body=bytearray()
while chunk:=await file.read(1024*1024):
body.extend(chunk)
if len(body)>settings().max_upload_bytes:
raise HTTPException(413,{'code':'upload_too_large','message':'Schematic exceeds configured upload size'})
try:detect_format(bytes(body))
except ParseError as exc:raise HTTPException(422,{'code':'invalid_schematic','message':str(exc)}) from exc
return name,bytes(body)
finally:await file.close()