Add Clear Data button to wipe county data folders

This commit is contained in:
zyphlar
2026-04-21 22:55:34 -07:00
parent 7aaff6be35
commit 6880382011
2 changed files with 38 additions and 0 deletions
+22
View File
@@ -251,6 +251,28 @@ def cancel_job():
except Exception as e: except Exception as e:
return jsonify({'error': str(e)}), 500 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']) @app.route('/api/upload-file', methods=['POST'])
def upload_file(): def upload_file():
"""Upload a shapefile ZIP to a path under /data""" """Upload a shapefile ZIP to a path under /data"""
+16
View File
@@ -376,6 +376,7 @@
<h1>OSM Import Tools</h1> <h1>OSM Import Tools</h1>
<div class="topbar-sep"></div> <div class="topbar-sep"></div>
<button class="btn-topbar" onclick="runScript('ls', '')">List Files</button> <button class="btn-topbar" onclick="runScript('ls', '')">List Files</button>
<button class="btn-topbar" onclick="clearData()" style="color:#f88;">Clear Data</button>
<div style="flex:1"></div> <div style="flex:1"></div>
<div class="config-group"> <div class="config-group">
<a href="/api/config/counties.yml" class="btn-topbar-icon" title="Download counties.yml">↓ counties.yml</a> <a href="/api/config/counties.yml" class="btn-topbar-icon" title="Download counties.yml">↓ counties.yml</a>
@@ -725,6 +726,21 @@
.finally(() => enableButtons()); .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) { function uploadConfig(filename, input) {
if (!input.files.length) return; if (!input.files.length) return;
const formData = new FormData(); const formData = new FormData();