|
|
|
|
@@ -410,8 +410,12 @@ Function Invoke-GiteaFileDownload {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
process {
|
|
|
|
|
Write-Verbose "Type: $type"
|
|
|
|
|
# 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,20 @@ 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 '/'
|
|
|
|
|
# Replace any URL encoded characters in the file name
|
|
|
|
|
$DownloadFilePath = [System.Uri]::UnescapeDataString($DownloadFilePath)
|
|
|
|
|
$DownloadFileName = $pathSegments[-1]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($PreserveRelativePath -and $outputPath) {
|
|
|
|
|
# If PreserveRelativePath is used, set up the directory structure
|
|
|
|
|
@@ -732,7 +746,7 @@ Function Get-GiteaChildItem {
|
|
|
|
|
$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)"
|
|
|
|
|
$item.download_url = "$giteaURL/api/v1/repos/$repoOwner/$repoName/media/$($item.path)?ref=$branch"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$itemObj = [PSCustomObject]@{
|
|
|
|
|
@@ -1029,4 +1043,4 @@ function Get-GiteaReleases {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Export-ModuleMember -Function Set-GiteaConfiguration, Get-GiteaConfiguration, Get-GiteaFileContent, Invoke-GiteaFileDownload, Get-GiteaChildItem, Get-GiteaLFSFile, Get-GiteaReleases
|
|
|
|
|
# Export-ModuleMember -Function Set-GiteaConfiguration, Get-GiteaConfiguration, Get-GiteaFileContent, Invoke-GiteaFileDownload, Get-GiteaChildItem, Get-GiteaReleases
|