1.2.0-rc1 #1
@@ -305,103 +305,6 @@ Function Get-GiteaLFSConfiguration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Get-GiteaLFSFile {
|
|
||||||
[CmdletBinding()]
|
|
||||||
param(
|
|
||||||
[string]$giteaURL,
|
|
||||||
[Parameter(ValueFromPipelineByPropertyName)]
|
|
||||||
[string]$repoOwner,
|
|
||||||
[Parameter(ValueFromPipelineByPropertyName)]
|
|
||||||
[string]$repoName,
|
|
||||||
[Parameter(ValueFromPipeline, ValueFromPipelineByPropertyName)]
|
|
||||||
[Alias('FullName')]
|
|
||||||
[string[]]$Path,
|
|
||||||
[Parameter(ValueFromPipelineByPropertyName)]
|
|
||||||
[string]$branch = "main",
|
|
||||||
[string]$token
|
|
||||||
)
|
|
||||||
|
|
||||||
begin {
|
|
||||||
# Initialize results array
|
|
||||||
$results = @()
|
|
||||||
|
|
||||||
# Use configuration if parameters aren't provided
|
|
||||||
if (-not $PSBoundParameters.ContainsKey('giteaURL') -or
|
|
||||||
-not $PSBoundParameters.ContainsKey('repoOwner') -or
|
|
||||||
-not $PSBoundParameters.ContainsKey('repoName') -or
|
|
||||||
-not $PSBoundParameters.ContainsKey('branch') -or
|
|
||||||
-not $PSBoundParameters.ContainsKey('token')) {
|
|
||||||
|
|
||||||
$config = Get-GiteaConfiguration
|
|
||||||
if ($config) {
|
|
||||||
if (-not $PSBoundParameters.ContainsKey('giteaURL')) { $giteaURL = $config.giteaURL }
|
|
||||||
if (-not $PSBoundParameters.ContainsKey('repoOwner')) { $repoOwner = $config.defaultOwner }
|
|
||||||
if (-not $PSBoundParameters.ContainsKey('repoName')) { $repoName = $config.defaultRepo }
|
|
||||||
if (-not $PSBoundParameters.ContainsKey('branch')) { $branch = $config.defaultBranch }
|
|
||||||
if (-not $PSBoundParameters.ContainsKey('token')) { $token = $config.token }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Validate that we have all required parameters
|
|
||||||
$missingParams = @()
|
|
||||||
if (-not $giteaURL) { $missingParams += "giteaURL" }
|
|
||||||
if (-not $repoOwner) { $missingParams += "repoOwner" }
|
|
||||||
if (-not $repoName) { $missingParams += "repoName" }
|
|
||||||
if (-not $token) { $missingParams += "token" }
|
|
||||||
|
|
||||||
if ($missingParams.Count -gt 0) {
|
|
||||||
throw "Missing required parameters: $($missingParams -join ', '). Either provide them directly or set them with Set-GiteaConfiguration."
|
|
||||||
}
|
|
||||||
|
|
||||||
Write-Verbose "Parameters:"
|
|
||||||
Write-Verbose "giteaURL: $giteaURL"
|
|
||||||
Write-Verbose "repoOwner: $repoOwner"
|
|
||||||
Write-Verbose "repoName: $repoName"
|
|
||||||
Write-Verbose "Path: $Path"
|
|
||||||
Write-Verbose "token: $token"
|
|
||||||
|
|
||||||
$headers = @{
|
|
||||||
"Authorization" = "token $token"
|
|
||||||
"Accept" = "application/json"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
process {
|
|
||||||
$paths = $path
|
|
||||||
foreach ($path in $paths) {
|
|
||||||
Write-Verbose "Processing path: $path"
|
|
||||||
# Normalize the path format - replace backslashes with forward slashes and trim trailing slashes
|
|
||||||
$normalizedPath = $path -replace '\\', '/' -replace '/$', ''
|
|
||||||
$encodedPath = [System.Uri]::EscapeDataString($normalizedPath)
|
|
||||||
Write-Verbose "Normalized path: $normalizedPath"
|
|
||||||
Write-Verbose "Encoded path: $encodedPath"
|
|
||||||
$url = "$giteaURL"
|
|
||||||
$url += "/api/v1/repos"
|
|
||||||
$url += "/$repoOwner"
|
|
||||||
$url += "/$repoName"
|
|
||||||
$url += "/media"
|
|
||||||
# Only add the path component if it's not empty
|
|
||||||
if (-not [string]::IsNullOrWhiteSpace($normalizedPath)) {
|
|
||||||
$url += "/$encodedPath"
|
|
||||||
}
|
|
||||||
$url += "?ref=$branch"
|
|
||||||
Write-Verbose "URL: $url"
|
|
||||||
|
|
||||||
try {
|
|
||||||
$response = Invoke-RestMethod -Uri $url -Method Get -Headers $headers -ResponseHeadersVariable ResponseHeaders -
|
|
||||||
}
|
|
||||||
catch {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
end {
|
|
||||||
return $ResponseHeaders
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Function Invoke-GiteaFileDownload {
|
Function Invoke-GiteaFileDownload {
|
||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
|
|||||||
Reference in New Issue
Block a user