checkBlob method

Future<String> checkBlob({
  1. required String sha256,
  2. bool useAuth = false,
  3. List<String>? serverUrls,
  4. String? pubkeyToFetchUserServerList,
})

checks if the blob exists on the server without downloading, useful to check before streaming a video via url
if serverUrls is null, the userServerList is fetched from nostr.
if the pukey has no UserServerList (kind: 10063), throws an error

returns the url of one server that has the blob e.g. https://myserver.com/hash.pdf
otherwise throws an error

Implementation

Future<String> checkBlob({
  required String sha256,
  bool useAuth = false,
  List<String>? serverUrls,
  String? pubkeyToFetchUserServerList,
}) async {
  Nip01Event? myAuthorization;

  if (useAuth) {
    _checkSigner();

    final now = DateTime.now().millisecondsSinceEpoch ~/ 1000;
    myAuthorization = Nip01Event(
      content: "get",
      pubKey: _signer.getPublicKey(),
      kind: kBlossom,
      createdAt: now,
      tags: [
        ["t", "get"],
        ["x", sha256],
        ["expiration", "${now + BLOSSOM_AUTH_EXPIRATION.inMilliseconds}"],
      ],
    );

    await _signer.sign(myAuthorization);
  }

  if (serverUrls == null) {
    if (pubkeyToFetchUserServerList == null) {
      throw Exception(
          "pubkeyToFetchUserServerList is null and serverUrls is null");
    }

    serverUrls ??= await _userServerList
        .getUserServerList(pubkeys: [pubkeyToFetchUserServerList]);
  }

  if (serverUrls == null) {
    throw Exception("User has no server list");
  }

  return _blossomImpl.checkBlob(
    sha256: sha256,
    authorization: myAuthorization,
    serverUrls: serverUrls,
  );
}