diff --git a/packages/komodo_wallet_build_transformer/lib/src/steps/fetch_coin_assets_build_step.dart b/packages/komodo_wallet_build_transformer/lib/src/steps/fetch_coin_assets_build_step.dart index 83a6f090..a8632a52 100644 --- a/packages/komodo_wallet_build_transformer/lib/src/steps/fetch_coin_assets_build_step.dart +++ b/packages/komodo_wallet_build_transformer/lib/src/steps/fetch_coin_assets_build_step.dart @@ -38,13 +38,8 @@ class FetchCoinAssetsBuildStep extends BuildStep { String? githubToken, }) { final config = buildConfig.coinCIConfig.copyWith( - // If the branch is `master`, use the repository mirror URL to avoid - // rate limiting issues. Consider refactoring config to allow branch - // specific mirror URLs to remove this workaround. - coinsRepoContentUrl: - buildConfig.coinCIConfig.isMainBranch - ? buildConfig.coinCIConfig.coinsRepoContentUrl - : buildConfig.coinCIConfig.rawContentUrl, + // Use the effective content URL which checks CDN mirrors + coinsRepoContentUrl: buildConfig.coinCIConfig.effectiveContentUrl, ); final provider = GithubApiProvider.withBaseUrl( diff --git a/packages/komodo_wallet_build_transformer/lib/src/steps/models/coin_assets/coin_build_config.dart b/packages/komodo_wallet_build_transformer/lib/src/steps/models/coin_assets/coin_build_config.dart index 9dca9a59..6390344e 100644 --- a/packages/komodo_wallet_build_transformer/lib/src/steps/models/coin_assets/coin_build_config.dart +++ b/packages/komodo_wallet_build_transformer/lib/src/steps/models/coin_assets/coin_build_config.dart @@ -22,6 +22,7 @@ class CoinBuildConfig { required this.mappedFiles, required this.mappedFolders, required this.concurrentDownloadsEnabled, + this.cdnBranchMirrors = const {}, }); /// Creates a new instance of [CoinBuildConfig] from a JSON object. @@ -42,17 +43,17 @@ class CoinBuildConfig { mappedFolders: Map.from( json['mapped_folders'] as Map? ?? {}, ), + cdnBranchMirrors: Map.from( + json['cdn_branch_mirrors'] as Map? ?? {}, + ), ); } - bool get isMainBranch => - coinsRepoBranch == 'master' || coinsRepoBranch == 'main'; - - String get rawContentUrl => - 'https://raw.githubusercontent.com/KomodoPlatform/coins/refs/heads/$coinsRepoBranch'; - - static const String cdnContentUrl = - 'https://api.github.com/repos/KomodoPlatform/coins'; + /// Gets the appropriate content URL for the current branch. + /// If a CDN mirror is configured for the branch, it uses that. + /// Otherwise, it falls back to the configured coinsRepoContentUrl. + String get effectiveContentUrl => + cdnBranchMirrors[coinsRepoBranch] ?? coinsRepoContentUrl; /// Indicates whether fetching updates of the coins assets are enabled. final bool fetchAtBuildEnabled; @@ -97,6 +98,12 @@ class CoinBuildConfig { /// corresponding paths in the GitHub repository. final Map mappedFolders; + /// A map of branch names to CDN mirror URLs. + /// When downloading assets, if the current branch has a CDN mirror configured, + /// it will be used instead of the default content URL. + /// This helps avoid rate limiting for commonly used branches. + final Map cdnBranchMirrors; + CoinBuildConfig copyWith({ String? bundledCoinsRepoCommit, bool? fetchAtBuildEnabled, @@ -108,6 +115,7 @@ class CoinBuildConfig { bool? concurrentDownloadsEnabled, Map? mappedFiles, Map? mappedFolders, + Map? cdnBranchMirrors, }) { return CoinBuildConfig( fetchAtBuildEnabled: fetchAtBuildEnabled ?? this.fetchAtBuildEnabled, @@ -123,6 +131,7 @@ class CoinBuildConfig { concurrentDownloadsEnabled ?? this.concurrentDownloadsEnabled, mappedFiles: mappedFiles ?? this.mappedFiles, mappedFolders: mappedFolders ?? this.mappedFolders, + cdnBranchMirrors: cdnBranchMirrors ?? this.cdnBranchMirrors, ); } @@ -138,6 +147,7 @@ class CoinBuildConfig { 'mapped_files': mappedFiles, 'mapped_folders': mappedFolders, 'concurrent_downloads_enabled': concurrentDownloadsEnabled, + 'cdn_branch_mirrors': cdnBranchMirrors, }; /// Loads the coins runtime update configuration synchronously from the diff --git a/packages/komodo_wallet_build_transformer/lib/src/steps/models/github/github_file.dart b/packages/komodo_wallet_build_transformer/lib/src/steps/models/github/github_file.dart index a60fee78..3bbb99ee 100644 --- a/packages/komodo_wallet_build_transformer/lib/src/steps/models/github/github_file.dart +++ b/packages/komodo_wallet_build_transformer/lib/src/steps/models/github/github_file.dart @@ -18,33 +18,34 @@ class GitHubFile { /// Creates a new instance of [GitHubFile] from a JSON map. factory GitHubFile.fromJson(Map data) => GitHubFile( - name: data['name'] as String, - path: data['path'] as String, - sha: data['sha'] as String, - size: data['size'] as int, - url: data['url'] as String?, - htmlUrl: data['html_url'] as String?, - gitUrl: data['git_url'] as String?, - downloadUrl: data['download_url'] as String, - type: data['type'] as String, - links: data['_links'] == null + name: data['name'] as String, + path: data['path'] as String, + sha: data['sha'] as String, + size: data['size'] as int, + url: data['url'] as String?, + htmlUrl: data['html_url'] as String?, + gitUrl: data['git_url'] as String?, + downloadUrl: data['download_url'] as String, + type: data['type'] as String, + links: + data['_links'] == null ? null : Links.fromJson(data['_links'] as Map), - ); + ); /// Converts the [GitHubFile] instance to a JSON map. Map toJson() => { - 'name': name, - 'path': path, - 'sha': sha, - 'size': size, - 'url': url, - 'html_url': htmlUrl, - 'git_url': gitUrl, - 'download_url': downloadUrl, - 'type': type, - '_links': links?.toJson(), - }; + 'name': name, + 'path': path, + 'sha': sha, + 'size': size, + 'url': url, + 'html_url': htmlUrl, + 'git_url': gitUrl, + 'download_url': downloadUrl, + 'type': type, + '_links': links?.toJson(), + }; /// The name of the file. final String name; @@ -103,15 +104,15 @@ class GitHubFile { ); } - GitHubFile withStaticHostingUrl(String branch) { - final staticHostingUrls = { - 'master': 'https://komodoplatform.github.io/coins', - }; + GitHubFile withStaticHostingUrl( + String branch, + Map cdnMirrors, + ) { + // Check if a CDN mirror is configured for this branch + final cdnUrl = cdnMirrors[branch]; return copyWith( - downloadUrl: staticHostingUrls.containsKey(branch) - ? '${staticHostingUrls[branch]}/$path' - : downloadUrl, + downloadUrl: cdnUrl != null ? '$cdnUrl/$path' : downloadUrl, ); } }