Add Clear Data button to wipe county data folders
This commit is contained in:
@@ -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"""
|
||||
|
||||
Reference in New Issue
Block a user