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 @@