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:
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"""