resolveFileCIDs method

Future<List<FileUploadResult>> resolveFileCIDs(
  1. String sessionUuid,
  2. int limit
)

Implementation

Future<List<FileUploadResult>> resolveFileCIDs(
    String sessionUuid, int limit) async {
  List<FileUploadResult> resolvedFiles = [];
  // Resolve CIDs for each file
  int retryTimes = 0;
  ApillonLogger.log('Resolving file CIDs...');
  while (resolvedFiles.isEmpty ||
      !resolvedFiles.every((f) => f.CID != null && f.CID != "")) {
    resolvedFiles = (await listFiles(
            IBucketFilesRequest(limit: limit, sessionUuid: sessionUuid)))
        .items
        .map((file) => FileUploadResult(
            fileName: file.name!,
            fileUuid: file.uuid,
            CID: file.CID,
            CIDv1: file.CIDv1))
        .toList();
    await Future.delayed(const Duration(milliseconds: 1000));
    if (++retryTimes >= 15) {
      ApillonLogger.log('Unable to resolve file CIDs', LogLevel.ERROR);
      return resolvedFiles;
    }
  }
  return resolvedFiles;
}