small fix in api

This commit is contained in:
Mateusz Gruszczyński
2026-03-04 10:33:48 +01:00
parent 721ad44960
commit 013a73e02d
3 changed files with 25 additions and 34 deletions

38
api.py
View File

@@ -439,30 +439,17 @@ def generate_raw_cidr():
}
)
if handler.needs_update():
handler.check_and_update()
update_progress(f'Loading data for {len(countries)} countries...', 0, 100)
update_progress('Loading networks...', 10, 100)
country_networks = {}
cache_sources = {}
total_countries = len(countries)
for idx, country in enumerate(countries, 1):
base_progress = int((idx - 1) / total_countries * 80)
update_progress(f'[{idx}/{total_countries}] Loading {country}...', base_progress, 100)
networks, source = get_country_networks_cached(country, use_cache=use_cache)
if networks:
country_networks[country] = networks
for i, country in enumerate(countries):
update_progress(f'Processing {country}...', 10 + (i * 60 // max(1, len(countries))), 100)
nets, source = get_country_networks_cached(country, use_cache=use_cache)
if nets:
country_networks[country] = nets
cache_sources[country] = source
next_progress = int(idx / total_countries * 80)
update_progress(
f'[{idx}/{total_countries}] {country}: {len(networks):,} networks ({source})',
next_progress,
100
)
if not country_networks:
clear_progress()
@@ -470,12 +457,7 @@ def generate_raw_cidr():
update_progress('Generating file...', 85, 100)
if 'txt' in app_type or 'cidr' in app_type or 'newline' in app_type:
config_text = ConfigGenerator.generate_raw_cidr(country_networks, aggregate=aggregate, redis_ips=None)
filename = f"blocklist_{'_'.join(sorted(countries))}.txt"
mimetype = 'text/plain'
elif 'json' in app_type:
if 'json' in app_type:
all_networks = []
for nets in country_networks.values():
all_networks.extend(nets)
@@ -507,8 +489,10 @@ def generate_raw_cidr():
mimetype = 'text/csv'
else:
clear_progress()
return jsonify({'success': False, 'error': f'Unknown format: {app_type}'}), 400
# TXT / CIDR / newline (default)
config_text = ConfigGenerator.generate_raw_cidr(country_networks, aggregate=aggregate, redis_ips=None)
filename = f"blocklist_{'_'.join(sorted(countries))}.txt"
mimetype = 'text/plain'
total_networks = sum(len(nets) for nets in country_networks.values())
stats = {