address codeql scan results (#8260)

This commit is contained in:
Blake Blackshear 2023-10-21 09:08:03 -04:00 committed by GitHub
parent e80b6d9e5b
commit c8b38bdd47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -261,7 +261,7 @@ def send_to_plus(id):
except Exception as ex: except Exception as ex:
logger.exception(ex) logger.exception(ex)
return make_response( return make_response(
jsonify({"success": False, "message": str(ex)}), jsonify({"success": False, "message": "Error uploading image"}),
400, 400,
) )
@ -281,7 +281,7 @@ def send_to_plus(id):
except Exception as ex: except Exception as ex:
logger.exception(ex) logger.exception(ex)
return make_response( return make_response(
jsonify({"success": False, "message": str(ex)}), jsonify({"success": False, "message": "Error uploading annotation"}),
400, 400,
) )
@ -352,7 +352,7 @@ def false_positive(id):
except Exception as ex: except Exception as ex:
logger.exception(ex) logger.exception(ex)
return make_response( return make_response(
jsonify({"success": False, "message": str(ex)}), jsonify({"success": False, "message": "Error uploading false positive"}),
400, 400,
) )
@ -455,8 +455,9 @@ def get_labels():
else: else:
events = Event.select(Event.label).distinct() events = Event.select(Event.label).distinct()
except Exception as e: except Exception as e:
logger.error(e)
return make_response( return make_response(
jsonify({"success": False, "message": f"Failed to get labels: {e}"}), 404 jsonify({"success": False, "message": "Failed to get labels"}), 404
) )
labels = sorted([e.label for e in events]) labels = sorted([e.label for e in events])
@ -469,9 +470,9 @@ def get_sub_labels():
try: try:
events = Event.select(Event.sub_label).distinct() events = Event.select(Event.sub_label).distinct()
except Exception as e: except Exception:
return make_response( return make_response(
jsonify({"success": False, "message": f"Failed to get sub_labels: {e}"}), jsonify({"success": False, "message": "Failed to get sub_labels"}),
404, 404,
) )
@ -649,7 +650,7 @@ def event_snapshot(id):
) )
# read snapshot from disk # read snapshot from disk
with open( with open(
os.path.join(CLIPS_DIR, f"{event.camera}-{id}.jpg"), "rb" os.path.join(CLIPS_DIR, f"{event.camera}-{event.id}.jpg"), "rb"
) as image_file: ) as image_file:
jpg_bytes = image_file.read() jpg_bytes = image_file.read()
except DoesNotExist: except DoesNotExist:
@ -741,7 +742,7 @@ def event_clip(id):
jsonify({"success": False, "message": "Clip not available"}), 404 jsonify({"success": False, "message": "Clip not available"}), 404
) )
file_name = f"{event.camera}-{id}.mp4" file_name = f"{event.camera}-{event.id}.mp4"
clip_path = os.path.join(CLIPS_DIR, file_name) clip_path = os.path.join(CLIPS_DIR, file_name)
if not os.path.isfile(clip_path): if not os.path.isfile(clip_path):
@ -994,8 +995,9 @@ def create_event(camera_name, label):
frame, frame,
) )
except Exception as e: except Exception as e:
logger.error(e)
return make_response( return make_response(
jsonify({"success": False, "message": f"An unknown error occurred: {e}"}), jsonify({"success": False, "message": "An unknown error occurred"}),
500, 500,
) )
@ -1188,11 +1190,12 @@ def config_set():
with open(config_file, "w") as f: with open(config_file, "w") as f:
f.write(old_raw_config) f.write(old_raw_config)
f.close() f.close()
logger.error(f"\nConfig Error:\n\n{str(traceback.format_exc())}")
return make_response( return make_response(
jsonify( jsonify(
{ {
"success": False, "success": False,
"message": f"\nConfig Error:\n\n{str(traceback.format_exc())}", "message": "Error parsing config. Check logs for error message.",
} }
), ),
400, 400,
@ -1366,7 +1369,10 @@ def latest_frame(camera_name):
@bp.route("/<camera_name>/recordings/<frame_time>/snapshot.png") @bp.route("/<camera_name>/recordings/<frame_time>/snapshot.png")
def get_snapshot_from_recording(camera_name: str, frame_time: str): def get_snapshot_from_recording(camera_name: str, frame_time: str):
if camera_name not in current_app.frigate_config.cameras: if camera_name not in current_app.frigate_config.cameras:
return "Camera named {} not found".format(camera_name), 404 return make_response(
jsonify({"success": False, "message": "Camera not found"}),
404,
)
frame_time = float(frame_time) frame_time = float(frame_time)
recording_query = ( recording_query = (
@ -1592,7 +1598,7 @@ def recording_clip(camera_name, start_ts, end_ts):
if clip.end_time > end_ts: if clip.end_time > end_ts:
playlist_lines.append(f"outpoint {int(end_ts - clip.start_time)}") playlist_lines.append(f"outpoint {int(end_ts - clip.start_time)}")
file_name = f"clip_{camera_name}_{start_ts}-{end_ts}.mp4" file_name = secure_filename(f"clip_{camera_name}_{start_ts}-{end_ts}.mp4")
path = os.path.join(CACHE_DIR, file_name) path = os.path.join(CACHE_DIR, file_name)
if not os.path.exists(path): if not os.path.exists(path):
@ -1760,7 +1766,7 @@ def vod_event(id):
404, 404,
) )
clip_path = os.path.join(CLIPS_DIR, f"{event.camera}-{id}.mp4") clip_path = os.path.join(CLIPS_DIR, f"{event.camera}-{event.id}.mp4")
if not os.path.isfile(clip_path): if not os.path.isfile(clip_path):
end_ts = ( end_ts = (
@ -1979,7 +1985,8 @@ def logs(service: str):
file.close() file.close()
return contents, 200 return contents, 200
except FileNotFoundError as e: except FileNotFoundError as e:
logger.error(e)
return make_response( return make_response(
jsonify({"success": False, "message": f"Could not find log file: {e}"}), jsonify({"success": False, "message": "Could not find log file"}),
500, 500,
) )