mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-08-22 13:47:29 +02:00
Fix content type for latest image API endpoint (#19555)
* Fix content type for latest image API endpoint Extension is an enum and .value needed to be appended. Additionally, fastapi's Response() automatically sets the content type when media_type is specified, so a Content-Type in the headers was redundant. * Remove another unneeded Content-Type
This commit is contained in:
parent
06539c925c
commit
6840415b6c
@ -142,15 +142,13 @@ def latest_frame(
|
|||||||
"regions": params.regions,
|
"regions": params.regions,
|
||||||
}
|
}
|
||||||
quality = params.quality
|
quality = params.quality
|
||||||
mime_type = extension
|
|
||||||
|
|
||||||
if extension == "png":
|
if extension == Extension.png:
|
||||||
quality_params = None
|
quality_params = None
|
||||||
elif extension == "webp":
|
elif extension == Extension.webp:
|
||||||
quality_params = [int(cv2.IMWRITE_WEBP_QUALITY), quality]
|
quality_params = [int(cv2.IMWRITE_WEBP_QUALITY), quality]
|
||||||
else:
|
else: # jpg or jpeg
|
||||||
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)
|
||||||
@ -193,12 +191,11 @@ def latest_frame(
|
|||||||
|
|
||||||
frame = cv2.resize(frame, dsize=(width, height), interpolation=cv2.INTER_AREA)
|
frame = cv2.resize(frame, dsize=(width, height), interpolation=cv2.INTER_AREA)
|
||||||
|
|
||||||
_, img = cv2.imencode(f".{extension}", frame, quality_params)
|
_, img = cv2.imencode(f".{extension.value}", frame, quality_params)
|
||||||
return Response(
|
return Response(
|
||||||
content=img.tobytes(),
|
content=img.tobytes(),
|
||||||
media_type=f"image/{mime_type}",
|
media_type=f"image/{extension.value}",
|
||||||
headers={
|
headers={
|
||||||
"Content-Type": f"image/{mime_type}",
|
|
||||||
"Cache-Control": "no-store"
|
"Cache-Control": "no-store"
|
||||||
if not params.store
|
if not params.store
|
||||||
else "private, max-age=60",
|
else "private, max-age=60",
|
||||||
@ -215,12 +212,11 @@ def latest_frame(
|
|||||||
|
|
||||||
frame = cv2.resize(frame, dsize=(width, height), interpolation=cv2.INTER_AREA)
|
frame = cv2.resize(frame, dsize=(width, height), interpolation=cv2.INTER_AREA)
|
||||||
|
|
||||||
_, img = cv2.imencode(f".{extension}", frame, quality_params)
|
_, img = cv2.imencode(f".{extension.value}", frame, quality_params)
|
||||||
return Response(
|
return Response(
|
||||||
content=img.tobytes(),
|
content=img.tobytes(),
|
||||||
media_type=f"image/{mime_type}",
|
media_type=f"image/{extension.value}",
|
||||||
headers={
|
headers={
|
||||||
"Content-Type": f"image/{mime_type}",
|
|
||||||
"Cache-Control": "no-store"
|
"Cache-Control": "no-store"
|
||||||
if not params.store
|
if not params.store
|
||||||
else "private, max-age=60",
|
else "private, max-age=60",
|
||||||
|
Loading…
Reference in New Issue
Block a user