From db6ee41f3cc48764f3f4a75b305b1d18a410741a Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Sat, 2 Sep 2023 04:42:33 -0600 Subject: [PATCH] Improve error checking and handling for recordings export (#7647) * Improve error checking and handling for recordings export * Cleanup * Remove order by --- frigate/http.py | 26 +++++++++++++++++++++++++- web/src/routes/Export.jsx | 12 +++++++++--- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/frigate/http.py b/frigate/http.py index 1cce6968e..f401e21e6 100644 --- a/frigate/http.py +++ b/frigate/http.py @@ -1617,7 +1617,31 @@ def vod_event(id): methods=["POST"], ) def export_recording(camera_name: str, start_time, end_time): - playback_factor = request.get_json(silent=True).get("playback", "realtime") + if not camera_name or not current_app.frigate_config.cameras.get(camera_name): + return make_response( + jsonify( + {"success": False, "message": f"{camera_name} is not a valid camera."} + ), + 404, + ) + + json: dict[str, any] = request.get_json(silent=True) or {} + playback_factor = json.get("playback", "realtime") + + recordings_count = ( + Recordings.select() + .where( + Recordings.start_time.between(start_time, end_time) + | Recordings.end_time.between(start_time, end_time) + | ((start_time > Recordings.start_time) & (end_time < Recordings.end_time)) + ) + .where(Recordings.camera == camera_name) + .count() + ) + + if recordings_count <= 0: + return "No recordings found for time range", 400 + exporter = RecordingExporter( current_app.frigate_config, camera_name, diff --git a/web/src/routes/Export.jsx b/web/src/routes/Export.jsx index 84a0f6009..1cac3c844 100644 --- a/web/src/routes/Export.jsx +++ b/web/src/routes/Export.jsx @@ -52,11 +52,17 @@ export default function Export() { axios .post(`export/${camera}/start/${start}/end/${end}`, { playback }) - .then(() => { - setMessage({ text: 'Successfully started export. View the file in the /exports folder.', error: false }); + .then((response) => { + if (response.status == 200) { + setMessage({ text: 'Successfully started export. View the file in the /exports folder.', error: false }); + } }) .catch((error) => { - setMessage({ text: `Failed to start export: ${error.response.data.message}`, error: true }); + if (error.response) { + setMessage({ text: `Failed to start export: ${error.response.data.message}`, error: true }); + } else { + setMessage({ text: `Failed to start export: ${error.message}`, error: true }); + } }); };