add a delete recordings button

This commit is contained in:
2026-01-20 17:45:23 +01:00
parent 7b77aa9042
commit 6852c74cd0
2 changed files with 40 additions and 1 deletions

View File

@@ -1842,7 +1842,7 @@ with st.expander("Record", expanded=False):
selected_device_name = None
# Recording controls
col_record, col_download = st.columns([1, 1])
col_record, col_download, col_delete = st.columns([1, 1, 1])
with col_record:
if st.button("Start Recording (5s)", disabled=not selected_device_name):
@@ -1879,6 +1879,22 @@ with st.expander("Record", expanded=False):
st.warning(f"Could not fetch recording: {e}")
else:
st.button("Download Last Recording", disabled=True, help="No recording available yet")
with col_delete:
if st.button("Delete Recordings", type="secondary"):
try:
r = requests.delete(f"{BACKEND_URL}/delete_recordings", timeout=10)
if r.ok:
result = r.json()
if result.get('success'):
st.success(f"Deleted {result.get('deleted_count', 0)} recording(s)")
st.session_state['last_recording'] = None
else:
st.error("Failed to delete recordings")
else:
st.error(f"Failed to delete recordings: {r.status_code}")
except Exception as e:
st.error(f"Error deleting recordings: {e}")
log.basicConfig(
level=os.environ.get('LOG_LEVEL', log.DEBUG),

View File

@@ -1413,6 +1413,29 @@ async def download_recording(filename: str):
raise HTTPException(status_code=500, detail=str(e))
@app.delete("/delete_recordings")
async def delete_recordings():
"""Delete all recordings in the recordings folder."""
try:
deleted_count = 0
for filename in os.listdir(RECORDINGS_DIR):
filepath = os.path.join(RECORDINGS_DIR, filename)
if os.path.isfile(filepath):
try:
os.remove(filepath)
deleted_count += 1
log.info("Deleted recording: %s", filename)
except Exception as e:
log.warning("Failed to delete %s: %s", filename, e)
log.info("Deleted %d recordings", deleted_count)
return {"success": True, "deleted_count": deleted_count}
except Exception as e:
log.error("Exception in /delete_recordings: %s", e, exc_info=True)
raise HTTPException(status_code=500, detail=str(e))
if __name__ == '__main__':
import os
os.chdir(os.path.dirname(__file__))