From b7e750bec67362803dc2d812063148f6ed33e9b3 Mon Sep 17 00:00:00 2001 From: Nick Mowen Date: Tue, 19 Sep 2023 09:02:18 -0600 Subject: [PATCH] Add ability to delete exports from exports screen --- frigate/http.py | 17 +++++++++++++ web/src/routes/Export.jsx | 52 ++++++++++++++++++++++++++++++++++----- 2 files changed, 63 insertions(+), 6 deletions(-) diff --git a/frigate/http.py b/frigate/http.py index d26a7bd2a..4638174da 100644 --- a/frigate/http.py +++ b/frigate/http.py @@ -34,6 +34,7 @@ from frigate.const import ( CACHE_DIR, CLIPS_DIR, CONFIG_DIR, + EXPORT_DIR, MAX_SEGMENT_DURATION, RECORD_DIR, ) @@ -1666,6 +1667,22 @@ def export_recording(camera_name: str, start_time, end_time): return "Starting export of recording", 200 +@bp.route("/export/", methods=["DELETE"]) +def export_delete(file_name: str): + file = os.path.join(EXPORT_DIR, file_name) + + if not os.path.exists(file): + return make_response( + jsonify( + {"success": False, "message": f"{file_name} not found."} + ), + 404, + ) + + os.unlink(file) + return "Successfully deleted file", 200 + + def imagestream(detected_frames_processor, camera_name, fps, height, draw_options): while True: # max out at specified FPS diff --git a/web/src/routes/Export.jsx b/web/src/routes/Export.jsx index 0b8a1452c..1fbc89d9d 100644 --- a/web/src/routes/Export.jsx +++ b/web/src/routes/Export.jsx @@ -1,14 +1,16 @@ import Heading from '../components/Heading'; import { useState } from 'preact/hooks'; -import useSWR from 'swr'; +import useSWR, { mutate } from 'swr'; import Button from '../components/Button'; import axios from 'axios'; import { baseUrl } from '../api/baseUrl'; import { Fragment } from 'preact'; import ActivityIndicator from '../components/ActivityIndicator'; import { Play } from '../icons/Play'; +import { Delete } from '../icons/Delete'; import LargeDialog from '../components/DialogLarge'; import VideoPlayer from '../components/VideoPlayer'; +import Dialog from '../components/Dialog'; export default function Export() { const { data: config } = useSWR('config'); @@ -30,9 +32,10 @@ export default function Export() { const [endDate, setEndDate] = useState(localISODate); const [endTime, setEndTime] = useState('23:59'); - // Playback States + // Export States const [selectedClip, setSelectedClip] = useState(); + const [deleteClip, setDeleteClip] = useState(); const onHandleExport = () => { if (camera == 'select') { @@ -74,6 +77,15 @@ export default function Export() { }); }; + const onHandleDelete = (clip) => { + axios.delete(`export/${clip}`).then((response) => { + if (response.status == 200) { + setDeleteClip(); + mutate(); + } + }); + }; + return (
Export @@ -84,7 +96,7 @@ export default function Export() { {selectedClip && ( -
+
Playback )} + {deleteClip && ( + +
+ Delete Export? +

Confirm deletion of {deleteClip}.

+
+
+ + +
+
+ )} +
@@ -184,7 +213,11 @@ export default function Export() { {exports && (
Exports - setSelectedClip(clip)} /> + setSelectedClip(clip)} + onDeleteClip={(clip) => setDeleteClip(clip)} + />
)}
@@ -192,7 +225,7 @@ export default function Export() { ); } -function Exports({ exports, onSetClip }) { +function Exports({ exports, onSetClip, onDeleteClip }) { return ( {exports.map((item) => ( @@ -209,9 +242,16 @@ function Exports({ exports, onSetClip }) { - + {item.name.substring(0, item.name.length - 4)} +
)}