diff --git a/PS-GiteaUtilities/PS-GiteaUtilities.psm1 b/PS-GiteaUtilities/PS-GiteaUtilities.psm1 index d094e22..1447807 100644 --- a/PS-GiteaUtilities/PS-GiteaUtilities.psm1 +++ b/PS-GiteaUtilities/PS-GiteaUtilities.psm1 @@ -717,17 +717,12 @@ Function Get-GiteaChildItem { } $itemObj = [PSCustomObject]@{ - filePath = $item.path - Path = $item.path - repoOwner = $repoOwner - repoName = $repoName - giteaURL = $giteaURL - downloadURL = $item.download_url - branch = $branch - type = $item.type name = $item.name + Path = $item.path + type = $item.type size = $item.size sha = $item.sha + downloadURL = $item.download_url Success = $true Error = $null Level = 0 @@ -786,21 +781,31 @@ Function Get-GiteaChildItem { } if ($isLFS) { $subItem.type = "lfs" + # Save the original download URL for LFS pointers to be used to populate the size and sha fields + $GitLFSPointerURL = $subItem.download_url + # Use the Gitea API to get the LFS pointer details + # 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]+)') { + $subItem.sha = $matches[1] + } + if ($lfsPointerContent -match 'size (\d+)') { + $subItem.size = [long]$matches[1] + } + # Set the download URL to the media endpoint for LFS files to download the actual file $subItem.download_url = "$giteaURL/api/v1/repos/$repoOwner/$repoName/media/$($subItem.path)" } $subItemObj = [PSCustomObject]@{ - filePath = $subItem.path - Path = $subItem.path - repoOwner = $repoOwner - repoName = $repoName - giteaURL = $giteaURL - downloadURL = $subItem.download_url - branch = $branch - type = $subItem.type name = $subItem.name + Path = $subItem.path + type = $subItem.type size = $subItem.size sha = $subItem.sha + downloadURL = $subItem.download_url Success = $true Error = $null Level = $currentLevel @@ -838,7 +843,6 @@ Function Get-GiteaChildItem { Write-Error "Failed to retrieve '$normalizedPath' from Gitea: $($_.Exception.Message)`n$($errorDetails | ConvertTo-Json -Depth 1 -Compress)" $results += [PSCustomObject]@{ - filePath = $normalizedPath Path = $normalizedPath repoOwner = $repoOwner repoName = $repoName