fix: offer mirror config or source switch when version fetch fails, no silent fallback

This commit is contained in:
i
2026-06-02 00:31:23 +08:00
parent 04f3f21f14
commit e5c70a7d8b
+38 -49
View File
@@ -1026,66 +1026,55 @@ function Run-QuickMode {
$script:SELECTED_SOURCE = if ($Source) { $Source } else { "npm" } $script:SELECTED_SOURCE = if ($Source) { $Source } else { "npm" }
$script:REMOTE_VERSION = Get-RemoteVersion -source $script:SELECTED_SOURCE $script:REMOTE_VERSION = Get-RemoteVersion -source $script:SELECTED_SOURCE
if (-not $script:REMOTE_VERSION) {
Write-Warn "无法从 $($script:SELECTED_SOURCE) 获取远程版本"
# 尝试备用来源
$allSources = @("github-official", "github-fork", "npm")
foreach ($fs in $allSources) {
if ($fs -eq $script:SELECTED_SOURCE) { continue }
Write-Info "尝试从 $fs 获取..."
$script:REMOTE_VERSION = Get-RemoteVersion -source $fs
if ($script:REMOTE_VERSION) {
$script:SELECTED_SOURCE = $fs
Write-Ok "从 $fs 获取版本成功: v$($script:REMOTE_VERSION)"
break
}
}
while (-not $script:REMOTE_VERSION) { while (-not $script:REMOTE_VERSION) {
Write-Err "无法从任何来源获取远程版本" Write-Warn "无法从 $($script:SELECTED_SOURCE) 获取远程版本"
Write-Host "" Write-Host ""
Write-Info "可能原因: 网络连接问题 / npm registry 或 GitHub API 访问受限" Write-Host "请选择操作:" -ForegroundColor Yellow
Write-Host "" Write-Host " 1) 配置镜像重试 ($($script:SELECTED_SOURCE))"
Write-Host "是否配置镜像以继续安装?" -ForegroundColor Yellow Write-Host " 2) 切换其他来源"
Write-Host " 1) 配置 npm 镜像 (如 https://registry.npmmirror.com)" Write-Host " 0) 退出"
Write-Host " 2) 配置 GitHub 镜像 (如 https://ghproxy.com)" Write-Host ""
Write-Host " 0) 退出" $choice = Read-Host "请输入选项 [0-2]"
Write-Host "" switch ($choice) {
$choice = Read-Host "请输入选项 [0-2]" "1" {
switch ($choice) { if ($script:SELECTED_SOURCE -eq "npm") {
"1" {
$reg = Read-Host "请输入 npm registry URL (Enter 使用默认 https://registry.npmmirror.com)" $reg = Read-Host "请输入 npm registry URL (Enter 使用默认 https://registry.npmmirror.com)"
$script:NPM_REGISTRY = if ($reg) { $reg } else { "https://registry.npmmirror.com" } $script:NPM_REGISTRY = if ($reg) { $reg } else { "https://registry.npmmirror.com" }
Write-Ok "npm registry 已设置为: $script:NPM_REGISTRY" Write-Ok "npm registry 已设置为: $script:NPM_REGISTRY"
$script:SELECTED_SOURCE = "npm" } else {
$script:REMOTE_VERSION = Get-RemoteVersion -source $script:SELECTED_SOURCE
if (-not $script:REMOTE_VERSION) {
Write-Warn "使用镜像后仍无法获取版本,请检查 URL 是否正确"
}
}
"2" {
$mirror = Read-Host "请输入 GitHub 镜像 URL (Enter 使用默认 https://ghproxy.com)" $mirror = Read-Host "请输入 GitHub 镜像 URL (Enter 使用默认 https://ghproxy.com)"
$script:GITHUB_MIRROR = if ($mirror) { $mirror } else { "https://ghproxy.com" } $script:GITHUB_MIRROR = if ($mirror) { $mirror } else { "https://ghproxy.com" }
Write-Ok "GitHub 镜像已设置为: $script:GITHUB_MIRROR" Write-Ok "GitHub 镜像已设置为: $script:GITHUB_MIRROR"
$allSources = @("github-official", "github-fork") }
foreach ($fs in $allSources) { $script:REMOTE_VERSION = Get-RemoteVersion -source $script:SELECTED_SOURCE
Write-Info "尝试从 $fs 获取..." if (-not $script:REMOTE_VERSION) {
$script:REMOTE_VERSION = Get-RemoteVersion -source $fs Write-Warn "使用镜像后仍无法获取版本,请检查 URL 是否正确"
if ($script:REMOTE_VERSION) { }
$script:SELECTED_SOURCE = $fs }
Write-Ok "从 $fs 获取版本成功: v$($script:REMOTE_VERSION)" "2" {
break $allSources = @("npm", "github-official", "github-fork")
} $found = $false
} foreach ($fs in $allSources) {
if (-not $script:REMOTE_VERSION) { if ($fs -eq $script:SELECTED_SOURCE) { continue }
Write-Warn "使用镜像后仍无法获取版本,请检查 URL 是否正确" Write-Info "尝试从 $fs 获取..."
$ver = Get-RemoteVersion -source $fs
if ($ver) {
$script:SELECTED_SOURCE = $fs
$script:REMOTE_VERSION = $ver
Write-Ok "从 $fs 获取版本成功: v$($script:REMOTE_VERSION)"
$found = $true
break
} }
} }
"0" { exit 1 } if (-not $found) {
default { Write-Warn "无效选项,请重新输入" } Write-Warn "所有来源均无法获取版本"
}
} }
Write-Host "" "0" { exit 1 }
default { Write-Warn "无效选项,请重新输入" }
} }
Write-Host ""
} }
Detect-Installed Detect-Installed