getSnapshots method
Get list of available snapshots from a mirror.
CoMaps CDN doesn't provide directory listings, so we dynamically probe versions based on the current date (going back 90 days). Results are sorted by date, newest first.
Implementation
Future<List<utils.Snapshot>> getSnapshots(Mirror mirror) async {
final snapshots = <utils.Snapshot>[];
final candidates = generateCandidateVersions();
// Probe candidate versions until we find one
for (final version in candidates) {
final testUrl = utils.MirrorService.buildDownloadUrl(
mirror.baseUrl, version, 'countries.txt');
try {
final response = await _client
.head(Uri.parse(testUrl))
.timeout(const Duration(seconds: 3));
if (response.statusCode == 200) {
snapshots.add(utils.Snapshot(version: version));
// Found one, we can stop or continue to find more
// For now, just find the first (latest) one to be efficient
break;
}
} catch (e) {
// Skip unavailable snapshots
}
}
// Sort by date, newest first
snapshots.sort((a, b) => b.date.compareTo(a.date));
return snapshots;
}