download method

Future<BlobResponse> download({
  1. required String url,
  2. List<String>? serverUrls,
  3. String? pubkey,
})

download a file from the server(s)
if its a blossom url (sha256 in url), blossom is used to download
if its a public url, the file is downloaded directly

serverUrls and pubkey are used to download from blossom
if serverUrls is null, the userServerList is fetched from nostr (using the pubkey).
if both serverUrls and pubkey are null, throws an error.

Implementation

Future<BlobResponse> download({
  required String url,
  List<String>? serverUrls,
  String? pubkey,
}) async {
  // Regular expression to match SHA256 in URLs
  final sha256Match = sha256Regex.firstMatch(url);

  if (sha256Match != null) {
    // This is a blossom URL, handle it using blossom protocol
    final sha256 = sha256Match.group(1)!;

    // Try to download using blossom
    return await _blossom.getBlob(
        sha256: sha256,
        serverUrls: serverUrls,
        pubkeyToFetchUserServerList: pubkey);
  } else {
    return await _blossom.directDownload(url: Uri.parse(url));
  }
}