From 4bd5f821a6cff3b40f42876213a265de5968e80c Mon Sep 17 00:00:00 2001 From: Willie Date: Mon, 16 Feb 2026 15:14:55 +0800 Subject: [PATCH] fix: avoid GitHub API rate limit in PowerShell install script Use redirect-based version detection (same as install.sh) instead of calling api.github.com directly, which is rate-limited to 60 req/hr for unauthenticated requests on shared IPs. --- install.ps1 | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/install.ps1 b/install.ps1 index 9bfdd3891..71286a421 100644 --- a/install.ps1 +++ b/install.ps1 @@ -30,13 +30,32 @@ function Get-Arch { } } -# Get latest version from GitHub API +# Get latest version using redirect (avoids API rate limit) function Get-LatestVersion { + try { + # Use redirect to get latest version (no API rate limit) + $response = Invoke-WebRequest -Uri "https://github.com/$Repo/releases/latest" ` + -MaximumRedirection 0 -UseBasicParsing -ErrorAction SilentlyContinue + } catch { + # PowerShell 5.1 throws on 3xx redirects; extract from the exception + $response = $_.Exception.Response + } + + $location = "" + if ($response -and $response.Headers -and $response.Headers["Location"]) { + $location = $response.Headers["Location"] + } + + if ($location -match "/tag/([^/\s]+)") { + return $Matches[1] + } + + # Fallback to API if redirect fails try { $release = Invoke-RestMethod -Uri "https://api.github.com/repos/$Repo/releases/latest" return $release.tag_name } catch { - Write-Err "Failed to get latest version: $_" + Write-Err "Failed to get latest version. Please check your internet connection." } }