Enhance Get-GiteaChildItem to retrieve and parse LFS pointer details for size and SHA; update download URL for LFS files.

This commit is contained in:
2025-04-25 15:44:37 -04:00
parent dfb34f240b
commit 8e1a5f187a

View File

@@ -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 # Save the original download URL for LFS pointers to be used to populate the size and sha fields
$GitLFSPointerURL = $item.download_url $GitLFSPointerURL = $item.download_url
# Use the Gitea API to get the LFS pointer details # Use the Gitea API to get the LFS pointer details
$lfsPointerResponse = Invoke-RestMethod -Uri $GitLFSPointerURL -Method Get -Headers $headers -ErrorAction Stop # For LFS files, we need to get the pointer file and parse it for details
Write-Debug "LFS Pointer Response: $($lfsPointerResponse | ConvertTo-Json -Depth 1 -Compress)" $lfsPointerContent = Invoke-RestMethod -Uri $GitLFSPointerURL -Method Get -Headers $headers -ErrorAction Stop
# Update the item with the LFS pointer details Write-Debug "LFS Pointer Content: $($lfsPointerContent)"
$item.size = $lfsPointerResponse.size
$item.sha = $lfsPointerResponse.sha # 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 # 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)" $item.download_url = "$giteaURL/api/v1/repos/$repoOwner/$repoName/media/$($item.path)"
} }