alroyso 1 year ago
parent
commit
4618208f01
1 changed files with 12 additions and 7 deletions
  1. 12 7
      scripts/init.dart

+ 12 - 7
scripts/init.dart

@@ -14,18 +14,23 @@ final binDir = Directory(path.join(assetsPath, 'bin'));
 final depDir = Directory(path.join(assetsPath, 'dep'));
 
 Future downloadLatestClashCore() async {
-  final version = "v1.16.0";
+  const version = "v1.16.0";
   final String clashCoreName = 'clash.meta-${ClashName.platform}-${ClashName.arch}-cgo-$version';
-  print(clashCoreName);
-  // final info = await dio.get('https://api.github.com/repos/MetaCubeX/Clash.Meta/releases');
-  // final Map<String, dynamic> latest = (info.data['assets'] as List<dynamic>).firstWhere((it) => (it['name'] as String).contains(clashCoreName));
-  //
+
+// Fetching release info from the GitHub API
+  final info = await dio.get('https://api.github.com/repos/MetaCubeX/Clash.Meta/releases/tags/$version');
+
+// Extracting the download URL from the API response based on the asset name
+  final Map<String, dynamic> latest = (info.data['assets'] as List<dynamic>)
+      .firstWhere((it) => (it['name'] as String).contains(clashCoreName));
+  final String downloadUrl = latest['browser_download_url'];
+
   final String newName = 'clash-${ClashName.platform}-${ClashName.arch}';
   final String name = "$clashCoreName.gz";
   final tempFile = File(path.join(binDir.path, '$name.temp'));
-//https://github.com/MetaCubeX/Clash.Meta/releases/download/v1.16.0/clash.meta-linux-amd64-cgo-v1.16.0.gz
+
   print('Downloading $name');
-  await dio.download("https://github.com/MetaCubeX/Clash.Meta/releases/download/v1.16.0/$name", tempFile.path);
+  await dio.download(downloadUrl, tempFile.path); // Use the obtained download URL
   print('Download Success');
 
   print('Unarchiving $name');