From 39ba6abcaace200cec4132f6432ac3fd10481583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Doin?= Date: Tue, 28 Mar 2023 15:29:11 +0200 Subject: [PATCH] feat(download): Add support for Github Enterprise --- lib/core.ps1 | 13 +++++++++++++ lib/install.ps1 | 3 +++ 2 files changed, 16 insertions(+) diff --git a/lib/core.ps1 b/lib/core.ps1 index a61f793072..7869ef8ab1 100644 --- a/lib/core.ps1 +++ b/lib/core.ps1 @@ -1243,6 +1243,19 @@ function handle_special_urls($url) } } + # Github enterprise + get_config PRIVATE_HOSTS | Where-Object { $_ -ne $null -and $url -match $_.match } | ForEach-Object { + if ($url -match '(?[^/]+)/(?[^/]+)/(?[^/]+)/releases/download/(?[^/]+)/(?[^/#]+)(?.*)') { + $headers = (ConvertFrom-StringData -StringData $_.Headers) + $privateUrl = "https://$($Matches.host)/api/v3/repos/$($Matches.owner)/$($Matches.repo)" + $assetUrl = "https://$($Matches.host)/api/v3/repos/$($Matches.owner)/$($Matches.repo)/releases/tags/$($Matches.tag)" + + if ((Invoke-RestMethod -Uri $privateUrl -Headers $headers).Private) { + $url = ((Invoke-RestMethod -Uri $assetUrl -Headers $headers).Assets | Where-Object -Property Name -EQ -Value $Matches.file).Url, $Matches.filename -join '' + } + } + } + return $url } diff --git a/lib/install.ps1 b/lib/install.ps1 index 22b76423ca..a82f0614ba 100644 --- a/lib/install.ps1 +++ b/lib/install.ps1 @@ -376,6 +376,9 @@ function Invoke-Download ($url, $to, $cookies, $progress) { (ConvertFrom-StringData -StringData $_.Headers).GetEnumerator() | ForEach-Object { $wreq.Headers[$_.Key] = $_.Value } + if ($null -ne $_.Accept) { + $wreq.Accept = $_.Accept + } } }