Fix 500 when an event thumbnail file is empty (#24110)

* fix 500 when an event thumbnail file is empty

* fix test
This commit is contained in:
Josh Hawkins
2026-09-12 07:30:04 -06:00
committed by Nicolas Mowen
parent 0aa086eefd
commit 96013a0487
3 changed files with 28 additions and 4 deletions
+9 -2
View File
@@ -1060,7 +1060,7 @@ async def event_thumbnail(
except DoesNotExist:
thumbnail_bytes = None
if thumbnail_bytes is None:
if not thumbnail_bytes:
# see if the object is currently being tracked
try:
camera_states = request.app.detected_frames_processor.get_camera_states()
@@ -1076,7 +1076,7 @@ async def event_thumbnail(
status_code=404,
)
if thumbnail_bytes is None:
if not thumbnail_bytes:
return JSONResponse(
content={"success": False, "message": "Event not found"},
status_code=404,
@@ -1085,6 +1085,13 @@ async def event_thumbnail(
img_as_np = np.frombuffer(thumbnail_bytes, dtype=np.uint8)
img = cv2.imdecode(img_as_np, flags=1)
if img is None:
# thumbnail on disk is truncated or corrupt
return JSONResponse(
content={"success": False, "message": "Event not found"},
status_code=404,
)
# android notifications prefer a 2:1 ratio
if format == "android":
img = cv2.copyMakeBorder(