diff --git a/bin/src/daemon.rs b/bin/src/daemon.rs index 8abea30..2ce836d 100644 --- a/bin/src/daemon.rs +++ b/bin/src/daemon.rs @@ -20,7 +20,7 @@ use crate::framebuffer::Framebuffer; use analysis::{get_analysis_status, run_analysis_thread, start_analysis, AnalysisCtrlMessage, AnalysisStatus}; use axum::response::Redirect; -use diag::{delete_recording, get_analysis_report, start_recording, stop_recording, DiagDeviceCtrlMessage}; +use diag::{delete_all_recordings, delete_recording, get_analysis_report, start_recording, stop_recording, DiagDeviceCtrlMessage}; use log::{info, error}; use qmdl_store::RecordingStoreError; use rayhunter::diag_device::DiagDevice; @@ -57,6 +57,7 @@ async fn run_server( .route("/api/start-recording", post(start_recording)) .route("/api/stop-recording", post(stop_recording)) .route("/api/delete-recording/*name", post(delete_recording)) + .route("/api/delete-all-recordings", post(delete_all_recordings)) .route("/api/analysis-report/*name", get(get_analysis_report)) .route("/api/analysis", get(get_analysis_status)) .route("/api/analysis/*name", post(start_analysis)) diff --git a/bin/src/diag.rs b/bin/src/diag.rs index 61a7931..b4b43e0 100644 --- a/bin/src/diag.rs +++ b/bin/src/diag.rs @@ -175,6 +175,20 @@ pub async fn delete_recording( Ok((StatusCode::ACCEPTED, "ok".to_string())) } +pub async fn delete_all_recordings(State(state): State>) -> Result<(StatusCode, String), (StatusCode, String)> { + if state.debug_mode { + return Err((StatusCode::FORBIDDEN, "server is in debug mode".to_string())); + } + let mut qmdl_store = state.qmdl_store_lock.write().await; + qmdl_store.delete_all_entries().await + .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("couldn't delete all recordings: {}", e)))?; + state.diag_device_ctrl_sender.send(DiagDeviceCtrlMessage::StopRecording).await + .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("couldn't send stop recording message: {}", e)))?; + state.ui_update_sender.send(framebuffer::DisplayState::Paused).await + .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("couldn't send ui update message: {}", e)))?; + Ok((StatusCode::ACCEPTED, "ok".to_string())) +} + pub async fn get_analysis_report(State(state): State>, Path(qmdl_name): Path) -> Result { let qmdl_store = state.qmdl_store_lock.read().await; let (entry_index, _) = if qmdl_name == "live" { diff --git a/bin/src/qmdl_store.rs b/bin/src/qmdl_store.rs index 9e1bca4..cce2ffe 100644 --- a/bin/src/qmdl_store.rs +++ b/bin/src/qmdl_store.rs @@ -298,6 +298,23 @@ impl RecordingStore { .map_err(RecordingStoreError::DeleteFileError)?; Ok(entry_to_delete) } + + pub async fn delete_all_entries(&mut self) -> Result<(), RecordingStoreError> { + self.close_current_entry().await?; + for entry in &self.manifest.entries { + let qmdl_filepath = entry.get_qmdl_filepath(&self.path); + let analysis_filepath = entry.get_analysis_filepath(&self.path); + tokio::fs::remove_file(qmdl_filepath) + .await + .map_err(RecordingStoreError::DeleteFileError)?; + tokio::fs::remove_file(analysis_filepath) + .await + .map_err(RecordingStoreError::DeleteFileError)?; + } + self.manifest.entries.drain(..); + self.write_manifest().await?; + Ok(()) + } } #[cfg(test)] diff --git a/bin/static/index.html b/bin/static/index.html index 7bb37c0..89e0fda 100644 --- a/bin/static/index.html +++ b/bin/static/index.html @@ -18,6 +18,7 @@
+
diff --git a/bin/static/js/main.js b/bin/static/js/main.js index 4f7af7d..42d23aa 100644 --- a/bin/static/js/main.js +++ b/bin/static/js/main.js @@ -215,6 +215,13 @@ async function stopRecording() { populateDivs(); } +async function deleteAllRecodings() { + if (window.confirm("Are you sure you want to permanently delete all of your recordings?")) { + await req('POST', '/api/delete-all-recordings'); + populateDivs(); + } +} + async function req(method, url) { const response = await fetch(url, { method: method,