getRegions method
Get list of available regions in a snapshot.
Fetches and parses countries.txt (JSON format) from the CoMaps CDN.
URL: <base>/maps/<version>/countries.txt
Implementation
Future<List<utils.MwmRegion>> getRegions(Mirror mirror, utils.Snapshot snapshot) async {
final url = utils.MirrorService.buildDownloadUrl(
mirror.baseUrl, snapshot.version, 'countries.txt');
try {
final response = await _client
.get(Uri.parse(url))
.timeout(const Duration(seconds: 30));
if (response.statusCode == 200) {
final json = jsonDecode(response.body) as Map<String, dynamic>;
final countriesData = utils.CountriesData.fromJson(json);
return countriesData.allRegions;
}
} catch (e) {
// countries.txt not available or parse error
}
throw Exception(
'Could not fetch regions from CoMaps CDN. '
'URL: $url',
);
}