Send clean image

This commit is contained in:
Nick Mowen 2022-02-15 21:48:51 -07:00
parent 47138e9237
commit cc4d48a6ef

View File

@ -355,27 +355,30 @@ def stats():
@bp.route("/<camera_name>/<label>/latest.jpg") @bp.route("/<camera_name>/<label>/latest.jpg")
def latest(camera_name, label): def latest(camera_name, label):
jpg_bytes = None png_bytes = None
if camera_name in current_app.frigate_config.cameras: if camera_name in current_app.frigate_config.cameras:
if label == "any":
label = "*"
event = ( event = (
Event.select() Event.select()
.where(Event.camera == camera_name) .where(Event.camera == camera_name)
.where(Event.label == "*" if label is "any" else label) .where(Event.label == label)
.where(Event.has_snapshot == True) .where(Event.has_snapshot == True)
.where(Event.end_time != None) .where(Event.end_time != None)
.order_by(Event.start_time.desc()) .order_by(Event.start_time.desc())
.get() .get()
) )
#event = events.first()
# read snapshot from disk # read snapshot from disk
with open( with open(
os.path.join(CLIPS_DIR, f"{event.camera}-{event.id}.jpg"), "rb" os.path.join(CLIPS_DIR, f"{event.camera}-{event.id}-clean.png"), "rb"
) as image_file: ) as image_file:
jpg_bytes = image_file.read() png_bytes = image_file.read()
response = make_response(jpg_bytes) response = make_response(png_bytes)
response.headers["Content-Type"] = "image/jpeg" response.headers["Content-Type"] = "image/png"
return response return response
else: else:
return "Camera named {} not found".format(camera_name), 404 return "Camera named {} not found".format(camera_name), 404