Fix mime types

This commit is contained in:
tpjanssen 2025-01-13 11:38:27 +01:00
parent ba810ee2a8
commit aacb9741cb

View File

@ -133,6 +133,7 @@ def latest_frame(
"regions": params.regions, "regions": params.regions,
} }
quality = params.quality quality = params.quality
mime_type = extension
if extension == "png": if extension == "png":
quality_params = None quality_params = None
@ -140,6 +141,7 @@ def latest_frame(
quality_params = [int(cv2.IMWRITE_WEBP_QUALITY), quality] quality_params = [int(cv2.IMWRITE_WEBP_QUALITY), quality]
else: else:
quality_params = [int(cv2.IMWRITE_JPEG_QUALITY), quality] quality_params = [int(cv2.IMWRITE_JPEG_QUALITY), quality]
mime_type = "jpeg"
if camera_name in request.app.frigate_config.cameras: if camera_name in request.app.frigate_config.cameras:
frame = frame_processor.get_current_frame(camera_name, draw_options) frame = frame_processor.get_current_frame(camera_name, draw_options)
@ -186,7 +188,7 @@ def latest_frame(
return Response( return Response(
content=img.tobytes(), content=img.tobytes(),
media_type=f"image/{extension}", media_type=f"image/{extension}",
headers={"Content-Type": f"image/{extension}", "Cache-Control": "no-store"}, headers={"Content-Type": f"image/{mime_type}", "Cache-Control": "no-store"},
) )
elif camera_name == "birdseye" and request.app.frigate_config.birdseye.restream: elif camera_name == "birdseye" and request.app.frigate_config.birdseye.restream:
frame = cv2.cvtColor( frame = cv2.cvtColor(
@ -205,7 +207,7 @@ def latest_frame(
return Response( return Response(
content=img.tobytes(), content=img.tobytes(),
media_type=f"image/{extension}", media_type=f"image/{extension}",
headers={"Content-Type": f"image/{extension}", "Cache-Control": "no-store"}, headers={"Content-Type": f"image/{mime_type}", "Cache-Control": "no-store"},
) )
else: else:
return JSONResponse( return JSONResponse(
@ -248,6 +250,7 @@ def get_snapshot_from_recording(
recording: Recordings = recording_query.get() recording: Recordings = recording_query.get()
time_in_segment = frame_time - recording.start_time time_in_segment = frame_time - recording.start_time
codec = "png" if format == "png" else "mjpeg" codec = "png" if format == "png" else "mjpeg"
mime_type = "png" if format == "png" else "jpeg"
config: FrigateConfig = request.app.frigate_config config: FrigateConfig = request.app.frigate_config
image_data = get_image_from_recording( image_data = get_image_from_recording(
@ -264,7 +267,7 @@ def get_snapshot_from_recording(
), ),
status_code=404, status_code=404,
) )
return Response(image_data, headers={"Content-Type": f"image/{format}"}) return Response(image_data, headers={"Content-Type": f"image/{mime_type}"})
except DoesNotExist: except DoesNotExist:
return JSONResponse( return JSONResponse(
content={ content={