fix(replay): stream sealed perception overlays
This commit is contained in:
@@ -15,7 +15,11 @@ from pydantic import BaseModel, ConfigDict, Field, StrictBool, field_validator,
|
||||
from starlette.concurrency import run_in_threadpool
|
||||
from starlette.types import Receive, Scope, Send
|
||||
|
||||
from k1link.compute import RecordedPerceptionOverlayError, RecordedPerceptionVideo
|
||||
from k1link.compute import (
|
||||
RecordedPerceptionOverlayArtifact,
|
||||
RecordedPerceptionOverlayError,
|
||||
RecordedPerceptionVideo,
|
||||
)
|
||||
from k1link.sessions import (
|
||||
LayoutConflictError,
|
||||
MaterializedRecording,
|
||||
@@ -899,8 +903,9 @@ def build_session_router(
|
||||
False,
|
||||
False,
|
||||
)
|
||||
materializer = getattr(perception_overlay_provider, "materialize", None)
|
||||
payload = await run_in_threadpool(
|
||||
perception_overlay_provider.render,
|
||||
materializer if callable(materializer) else perception_overlay_provider.render,
|
||||
session_id,
|
||||
application_id=request.application_id,
|
||||
recording_id=request.recording_id,
|
||||
@@ -921,6 +926,32 @@ def build_session_router(
|
||||
) from exc
|
||||
if payload is None:
|
||||
return Response(status_code=204, headers={"Cache-Control": "no-store"})
|
||||
if isinstance(payload, RecordedPerceptionOverlayArtifact):
|
||||
try:
|
||||
metadata = payload.path.stat()
|
||||
except OSError as exc:
|
||||
raise HTTPException(
|
||||
status_code=500,
|
||||
detail="Не удалось подготовить слой распознавания.",
|
||||
) from exc
|
||||
if not metadata.st_size == payload.byte_length:
|
||||
raise HTTPException(
|
||||
status_code=500,
|
||||
detail="Не удалось подготовить слой распознавания.",
|
||||
)
|
||||
return FileResponse(
|
||||
path=payload.path,
|
||||
media_type="application/vnd.rerun.rrd",
|
||||
filename="perception.rrd",
|
||||
content_disposition_type="inline",
|
||||
stat_result=metadata,
|
||||
headers={
|
||||
"Cache-Control": "private, no-cache, no-transform",
|
||||
"Content-Length": str(payload.byte_length),
|
||||
"ETag": f'"sha256:{payload.sha256}"',
|
||||
"X-Content-Type-Options": "nosniff",
|
||||
},
|
||||
)
|
||||
return Response(
|
||||
content=payload,
|
||||
media_type="application/vnd.rerun.rrd",
|
||||
|
||||
Reference in New Issue
Block a user