From 6880382011998c444aae4a50d47cf3948f50e602 Mon Sep 17 00:00:00 2001 From: zyphlar Date: Tue, 21 Apr 2026 22:55:34 -0700 Subject: [PATCH] Add Clear Data button to wipe county data folders --- web/server.py | 22 ++++++++++++++++++++++ web/templates/index.html | 16 ++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/web/server.py b/web/server.py index 7e94281..ce16644 100644 --- a/web/server.py +++ b/web/server.py @@ -251,6 +251,28 @@ def cancel_job(): except Exception as e: return jsonify({'error': str(e)}), 500 +@app.route('/api/clear-data', methods=['POST']) +def clear_data(): + """Delete all files from every county data directory under /data.""" + counties = get_counties() + removed = [] + errors = [] + for county in counties: + county_dir = f'/data/{county["id"]}' + if not os.path.isdir(county_dir): + continue + for fname in os.listdir(county_dir): + fpath = os.path.join(county_dir, fname) + if os.path.isfile(fpath): + try: + os.remove(fpath) + removed.append(f'{county["id"]}/{fname}') + except Exception as e: + errors.append(str(e)) + if errors: + return jsonify({'error': '; '.join(errors)}), 500 + return jsonify({'success': True, 'removed': removed}) + @app.route('/api/upload-file', methods=['POST']) def upload_file(): """Upload a shapefile ZIP to a path under /data""" diff --git a/web/templates/index.html b/web/templates/index.html index 4889dc7..c6686c7 100644 --- a/web/templates/index.html +++ b/web/templates/index.html @@ -376,6 +376,7 @@

OSM Import Tools

+
↓ counties.yml @@ -725,6 +726,21 @@ .finally(() => enableButtons()); } + function clearData() { + if (!confirm('Delete all downloaded and processed files from all county folders?')) return; + fetch('/api/clear-data', { method: 'POST' }) + .then(r => r.json()) + .then(data => { + if (data.error) { + showStatus(`Error: ${data.error}`, 'error'); + } else { + showStatus(`Cleared ${data.removed.length} file(s).`, 'success'); + setTimeout(() => window.location.reload(), 800); + } + }) + .catch(err => showStatus(`Error: ${err.message}`, 'error')); + } + function uploadConfig(filename, input) { if (!input.files.length) return; const formData = new FormData();