checkBlob method

  1. @override
Future<String> checkBlob({
  1. required String sha256,
  2. required List<String> serverUrls,
  3. Nip01Event? authorization,
})
override

Checks if the blob exists on the server If authorization is null, the server must be public

returns one server that has the blob

Implementation

@override
Future<String> checkBlob({
  required String sha256,
  required List<String> serverUrls,
  Nip01Event? authorization,
}) async {
  Exception? lastError;

  final headers = <String, String>{};

  if (authorization != null) {
    headers['Authorization'] = "Nostr ${authorization.toBase64()}";
  }

  for (final url in serverUrls) {
    try {
      final response = await client.head(
        url: Uri.parse('$url/$sha256'),
      );

      if (response.statusCode == 200) {
        return '$url/$sha256';
      }
      lastError = Exception('HTTP ${response.statusCode}');
    } catch (e) {
      lastError = e is Exception ? e : Exception(e.toString());
    }
  }

  throw Exception(
      'Failed to check blob from any of the servers. Last error: $lastError');
}