getBuildConfig method

Future<BuildInfo?> getBuildConfig()

Implementation

Future<BuildInfo?> getBuildConfig() async {
  final appwriteServer = AppwriteServer(environment);

  final databases = appwriteServer.databases;
  final documents = await databases.listDocuments(
    databaseId: environment.databaseId,
    collectionId: environment.collectionId,
    queries: [
      Query.equal('platform', platform),
      Query.equal('branch', branch),
      Query.orderDesc('build_time'),
    ],
  );

  if (documents.documents.isEmpty) {
    return null;
  }

  /// 按照最新创建时间排序
  documents.documents.sort((a, b) {
    return DateTime.parse(a.$createdAt)
        .compareTo(DateTime.parse(b.$createdAt));
  });

  final document = documents.documents.last;
  final buildInfo = BuildInfo.fromJson({
    'flutter': JSON(document.data)['flutter_conmit'].stringValue,
    'unity': BuildUnityConfig.fromJson({
      'cache': JSON(document.data)['unity_cache_commit'].stringValue,
      'log': JSON(document.data)['unity_log_commit'].stringValue,
    }).toJson(),
  });
  return buildInfo;
}