From edb1501f40735023a5e9d2aa95d1fc00aa073568 Mon Sep 17 00:00:00 2001 From: Raymond LaRose Date: Tue, 27 May 2025 12:38:58 -0400 Subject: [PATCH] Bump module version to 1.4.4 and enhance Invoke-GiteaFileDownload to handle LFS file downloads with type inference and properly format file path based on API URL --- PS-GiteaUtilities/PS-GiteaUtilities.psd1 | 2 +- PS-GiteaUtilities/PS-GiteaUtilities.psm1 | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/PS-GiteaUtilities/PS-GiteaUtilities.psd1 b/PS-GiteaUtilities/PS-GiteaUtilities.psd1 index 7a34c82..32b7833 100644 --- a/PS-GiteaUtilities/PS-GiteaUtilities.psd1 +++ b/PS-GiteaUtilities/PS-GiteaUtilities.psd1 @@ -12,7 +12,7 @@ RootModule = 'PS-GiteaUtilities.psm1' # Version number of this module. -ModuleVersion = '1.4.3' +ModuleVersion = '1.4.4' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/PS-GiteaUtilities/PS-GiteaUtilities.psm1 b/PS-GiteaUtilities/PS-GiteaUtilities.psm1 index aa9e49c..3e1f33e 100644 --- a/PS-GiteaUtilities/PS-GiteaUtilities.psm1 +++ b/PS-GiteaUtilities/PS-GiteaUtilities.psm1 @@ -410,8 +410,12 @@ Function Invoke-GiteaFileDownload { } process { + # If type is not provided, check for any hints for cases such as LFS where a type can be inferred and special handling is needed + If($downloadURL -match "/api/v1/repos/[^/]+/[^/]+/media/") { + $type = "lfs" + } + Write-Verbose "Type: $type" - # Handle the type parameter # Skip directories and provide a verbose message @@ -447,10 +451,18 @@ Function Invoke-GiteaFileDownload { # Separate the URL into its components: Gitea URL, Repo Owner, Repo Name, branch, file path, and file name $uri = New-Object System.Uri($downloadURL) $pathSegments = $uri.AbsolutePath.Trim('/').Split('/') - # Everything after the branch + 1 segment is considered the file path with the last segment being the file name - $branchIndex = [Array]::IndexOf($pathSegments, "branch") + 2 - $DownloadFilePath = $pathSegments[$branchIndex..($pathSegments.Length - 2)] -join '/' - $DownloadFileName = $pathSegments[-1] + If($type -eq "lfs") { + # Everything after the media segment is considered the file path with the last segment being the file name + $branchIndex = [Array]::IndexOf($pathSegments, "media") + 1 + $DownloadFilePath = $pathSegments[$branchIndex..($pathSegments.Length - 2)] -join '/' + $DownloadFileName = $pathSegments[-1] + } + Else { + # Everything after the branch + 1 segment is considered the file path with the last segment being the file name + $branchIndex = [Array]::IndexOf($pathSegments, "branch") + 2 + $DownloadFilePath = $pathSegments[$branchIndex..($pathSegments.Length - 2)] -join '/' + $DownloadFileName = $pathSegments[-1] + } if ($PreserveRelativePath -and $outputPath) { # If PreserveRelativePath is used, set up the directory structure