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.
This commit is contained in:
Willie
2026-02-16 15:14:55 +08:00
parent bda787362f
commit 4bd5f821a6
+21 -2
View File
@@ -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."
}
}