From 2fbfbf614b48553f3299840a372e7d208c170aa8 Mon Sep 17 00:00:00 2001 From: Jason Hunter Date: Sun, 11 Jul 2021 20:42:23 -0400 Subject: [PATCH] add download option on clips and snapshots --- frigate/http.py | 18 ++++++++++++++---- web/src/routes/Event.jsx | 14 ++++++++++++-- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/frigate/http.py b/frigate/http.py index b8a1865fc..03903967b 100644 --- a/frigate/http.py +++ b/frigate/http.py @@ -187,6 +187,7 @@ def event_thumbnail(id): @bp.route("/events//snapshot.jpg") def event_snapshot(id): + download = request.args.get("download", type=bool) jpg_bytes = None try: event = Event.get(Event.id == id) @@ -222,11 +223,17 @@ def event_snapshot(id): response = make_response(jpg_bytes) response.headers["Content-Type"] = "image/jpg" + if download: + response.headers[ + "Content-Disposition" + ] = f"attachment; filename=snapshot-{id}.jpg" return response @bp.route("/events//clip.mp4") def event_clip(id): + download = request.args.get("download", type=bool) + event: Event = Event.get(Event.id == id) if event is None: @@ -246,7 +253,7 @@ def event_clip(id): return send_file( clip_path, mimetype="video/mp4", - as_attachment=True, + as_attachment=download, attachment_filename=f"{event.camera}_{start_ts}-{end_ts}.mp4", ) @@ -548,6 +555,8 @@ def recordings(camera_name): @bp.route("//start//end//clip.mp4") @bp.route("//start//end//clip.mp4") def recording_clip(camera, start_ts, end_ts): + download = request.args.get("download", type=bool) + recordings = ( Recordings.select() .where( @@ -615,9 +624,10 @@ def recording_clip(camera, start_ts, end_ts): response = make_response(mp4_bytes) response.mimetype = "video/mp4" - response.headers[ - "Content-Disposition" - ] = f"attachment; filename={camera}_{start_ts}-{end_ts}.mp4" + if download: + response.headers[ + "Content-Disposition" + ] = f"attachment; filename={camera}_{start_ts}-{end_ts}.mp4" return response diff --git a/web/src/routes/Event.jsx b/web/src/routes/Event.jsx index f1d4aea87..3cbe4e60f 100644 --- a/web/src/routes/Event.jsx +++ b/web/src/routes/Event.jsx @@ -127,10 +127,20 @@ export default function Event({ eventId }) { onReady={(player) => {}} />
- -