From c28422313ebb36397dbf36425f20f5e02eac5e90 Mon Sep 17 00:00:00 2001 From: romanitho <96626929+Romanitho@users.noreply.github.com> Date: Fri, 17 Nov 2023 15:05:29 +0100 Subject: [PATCH] API Rate limite workarround https://docs.github.com/en/github-ae@latest/rest/overview/rate-limits-for-the-rest-api#primary-rate-limit-for-unauthenticated-users 60 requests per hour --- .../functions/Get-WAUAvailableVersion.ps1 | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/Winget-AutoUpdate/functions/Get-WAUAvailableVersion.ps1 b/Winget-AutoUpdate/functions/Get-WAUAvailableVersion.ps1 index c2241ab..90c90fb 100644 --- a/Winget-AutoUpdate/functions/Get-WAUAvailableVersion.ps1 +++ b/Winget-AutoUpdate/functions/Get-WAUAvailableVersion.ps1 @@ -8,18 +8,34 @@ function Get-WAUAvailableVersion { #Log Write-ToLog "WAU AutoUpdate Pre-release versions is Enabled" "Cyan" - #Get latest pre-release info - $WAUurl = 'https://api.github.com/repos/Romanitho/Winget-AutoUpdate/releases' + try { + #Get latest pre-release info + $WAUurl = 'https://api.github.com/repos/Romanitho/Winget-AutoUpdate/releases' + $WAUAvailableVersion = ((Invoke-WebRequest $WAUurl -UseBasicParsing | ConvertFrom-Json)[0].tag_name).Replace("v", "") + } + catch { + $url = "https://github.com/Romanitho/Winget-AutoUpdate/releases" + $link = ((Invoke-WebRequest $url -UseBasicParsing).Links.href -match "/Winget-AutoUpdate/releases/tag/v*")[0] + $WAUAvailableVersion = $link.Trim().Split("v")[-1] + } } else { - #Get latest stable info - $WAUurl = 'https://api.github.com/repos/Romanitho/Winget-AutoUpdate/releases/latest' + try { + #Get latest stable info + $WAUurl = 'https://api.github.com/repos/Romanitho/Winget-AutoUpdate/releases/latest' + $WAUAvailableVersion = ((Invoke-WebRequest $WAUurl -UseBasicParsing | ConvertFrom-Json)[0].tag_name).Replace("v", "") + } + catch { + $url = "https://github.com/Romanitho/Winget-AutoUpdate/releases/latest" + $link = ((Invoke-WebRequest $url -UseBasicParsing).Links.href -match "/Winget-AutoUpdate/releases/tag/v*")[0] + $WAUAvailableVersion = $link.Trim().Split("v")[-1] + } } #Return version - return ((Invoke-WebRequest $WAUurl -UseBasicParsing | ConvertFrom-Json)[0].tag_name).Replace("v", "") + return $WAUAvailableVersion -} +} \ No newline at end of file