From 8e1a5f187ae0656db6001b0fb9cb69d790794929 Mon Sep 17 00:00:00 2001 From: Raymond LaRose Date: Fri, 25 Apr 2025 15:44:37 -0400 Subject: [PATCH] Enhance Get-GiteaChildItem to retrieve and parse LFS pointer details for size and SHA; update download URL for LFS files. --- PS-GiteaUtilities/PS-GiteaUtilities.psm1 | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/PS-GiteaUtilities/PS-GiteaUtilities.psm1 b/PS-GiteaUtilities/PS-GiteaUtilities.psm1 index 77cf0b3..d094e22 100644 --- a/PS-GiteaUtilities/PS-GiteaUtilities.psm1 +++ b/PS-GiteaUtilities/PS-GiteaUtilities.psm1 @@ -701,11 +701,17 @@ Function Get-GiteaChildItem { # Save the original download URL for LFS pointers to be used to populate the size and sha fields $GitLFSPointerURL = $item.download_url # Use the Gitea API to get the LFS pointer details - $lfsPointerResponse = Invoke-RestMethod -Uri $GitLFSPointerURL -Method Get -Headers $headers -ErrorAction Stop - Write-Debug "LFS Pointer Response: $($lfsPointerResponse | ConvertTo-Json -Depth 1 -Compress)" - # Update the item with the LFS pointer details - $item.size = $lfsPointerResponse.size - $item.sha = $lfsPointerResponse.sha + # For LFS files, we need to get the pointer file and parse it for details + $lfsPointerContent = Invoke-RestMethod -Uri $GitLFSPointerURL -Method Get -Headers $headers -ErrorAction Stop + Write-Debug "LFS Pointer Content: $($lfsPointerContent)" + + # Parse the LFS pointer to extract size and SHA + if ($lfsPointerContent -match 'oid sha256:([a-f0-9]+)') { + $item.sha = $matches[1] + } + if ($lfsPointerContent -match 'size (\d+)') { + $item.size = [long]$matches[1] + } # Set the download URL to the media endpoint for LFS files to download the actual file $item.download_url = "$giteaURL/api/v1/repos/$repoOwner/$repoName/media/$($item.path)" }