getLatestVersionFromBinaryRepo function
Get the latest version from a binary repo channel endpoint.
Implementation
Future<String> getLatestVersionFromBinaryRepo({
String channel = 'latest',
required String baseUrl,
String? authUsername,
String? authPassword,
}) async {
final startTime = DateTime.now().millisecondsSinceEpoch;
final client = HttpClient();
try {
final request = await client.getUrl(Uri.parse('$baseUrl/$channel'));
request.headers.set('Accept', 'text/plain');
if (authUsername != null && authPassword != null) {
request.headers.set(
'Authorization',
'Basic ${base64Encode(utf8.encode('$authUsername:$authPassword'))}',
);
}
final response = await request.close().timeout(const Duration(seconds: 30));
final body = await response.transform(utf8.decoder).join();
final latencyMs = DateTime.now().millisecondsSinceEpoch - startTime;
_logDebug('Version check from $baseUrl/$channel took ${latencyMs}ms');
return body.trim();
} catch (e) {
final latencyMs = DateTime.now().millisecondsSinceEpoch - startTime;
_logDebug('Version check failed after ${latencyMs}ms: $e');
rethrow;
} finally {
client.close();
}
}