Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,18 @@ class GitHubFileDownloader {
}
}

Future<String> _fetchFileContent(String fileUrl, String repoCommit) async {
final isRawContentUrl = fileUrl.startsWith(
Future<String> _fetchFileContent(
String relativeFilePath,
String repoCommit,
) async {
final isRawContentUrl = relativeFilePath.startsWith(
'https://raw.githubusercontent.com',
);

final fileContentUrl = Uri.parse(
isRawContentUrl
? '$repoContentUrl/$repoCommit/$fileUrl'
: '$repoContentUrl/$fileUrl',
? '$repoContentUrl/$repoCommit/$relativeFilePath'
: '$repoContentUrl/$relativeFilePath',
);

_log.fine('Fetching file content from: $fileContentUrl');
Expand All @@ -154,6 +157,15 @@ class GitHubFileDownloader {
return response.body;
}

String _buildFileDownloadUrl(String filePath, String repoCommit) {
final isRawContentUrl = repoContentUrl.contains(
'raw.githubusercontent.com',
);
return isRawContentUrl
? '$repoContentUrl/$repoCommit/$filePath'
: '$repoContentUrl/$filePath';
}

/// Downloads the mapped folders from a GitHub repository at a specific commit
///
/// The [repoCommit] parameter specifies the commit hash of the repository.
Expand Down Expand Up @@ -184,7 +196,7 @@ class GitHubFileDownloader {
_log.fine(
'Downloading ${entry.value.length} files from ${entry.key}',
);
await _downloadFolderContents(entry.key, entry.value);
await _downloadFolderContents(entry.key, entry.value, repoCommit);
}).toList();

await Future.wait(downloadFutures);
Expand All @@ -210,7 +222,7 @@ class GitHubFileDownloader {
);
for (final entry in folderContents.entries) {
_log.fine('Downloading ${entry.value.length} files from ${entry.key}');
await _downloadFolderContentsSync(entry.key, entry.value);
await _downloadFolderContentsSync(entry.key, entry.value, repoCommit);
}

sendPort?.send(
Expand All @@ -226,9 +238,19 @@ class GitHubFileDownloader {
Future<void> _downloadFolderContentsSync(
String key,
List<GitHubFile> value,
String repoCommit,
) async {
final filesWithCdn =
value
.map(
(file) => file.copyWith(
downloadUrl: _buildFileDownloadUrl(file.path, repoCommit),
),
)
.toList();

await for (final GitHubFileDownloadEvent event in downloadFiles(
value,
filesWithCdn,
key,
)) {
switch (event.event) {
Expand All @@ -253,12 +275,16 @@ class GitHubFileDownloader {
Future<void> _downloadFolderContents(
String key,
List<GitHubFile> value,
String repoCommit,
) async {
final List<Future<void>> downloadFutures =
value.map((file) async {
final fileWithCdn = file.copyWith(
downloadUrl: _buildFileDownloadUrl(file.path, repoCommit),
);
await for (final GitHubFileDownloadEvent event in downloadFiles([
file,
], key)) {
fileWithCdn,
], key,)) {
Comment thread
takenagain marked this conversation as resolved.
Outdated
switch (event.event) {
case GitHubDownloadEvent.downloaded:
_downloadedFiles++;
Expand Down