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
+19 -30
View File
@@ -1026,59 +1026,49 @@ 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 " 2) 配置 GitHub 镜像 (如 https://ghproxy.com)"
Write-Host " 0) 退出" Write-Host " 0) 退出"
Write-Host "" Write-Host ""
$choice = Read-Host "请输入选项 [0-2]" $choice = Read-Host "请输入选项 [0-2]"
switch ($choice) { switch ($choice) {
"1" { "1" {
if ($script:SELECTED_SOURCE -eq "npm") {
$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 {
$mirror = Read-Host "请输入 GitHub 镜像 URL (Enter 使用默认 https://ghproxy.com)"
$script:GITHUB_MIRROR = if ($mirror) { $mirror } else { "https://ghproxy.com" }
Write-Ok "GitHub 镜像已设置为: $script:GITHUB_MIRROR"
}
$script:REMOTE_VERSION = Get-RemoteVersion -source $script:SELECTED_SOURCE $script:REMOTE_VERSION = Get-RemoteVersion -source $script:SELECTED_SOURCE
if (-not $script:REMOTE_VERSION) { if (-not $script:REMOTE_VERSION) {
Write-Warn "使用镜像后仍无法获取版本,请检查 URL 是否正确" Write-Warn "使用镜像后仍无法获取版本,请检查 URL 是否正确"
} }
} }
"2" { "2" {
$mirror = Read-Host "请输入 GitHub 镜像 URL (Enter 使用默认 https://ghproxy.com)" $allSources = @("npm", "github-official", "github-fork")
$script:GITHUB_MIRROR = if ($mirror) { $mirror } else { "https://ghproxy.com" } $found = $false
Write-Ok "GitHub 镜像已设置为: $script:GITHUB_MIRROR"
$allSources = @("github-official", "github-fork")
foreach ($fs in $allSources) { foreach ($fs in $allSources) {
if ($fs -eq $script:SELECTED_SOURCE) { continue }
Write-Info "尝试从 $fs 获取..." Write-Info "尝试从 $fs 获取..."
$script:REMOTE_VERSION = Get-RemoteVersion -source $fs $ver = Get-RemoteVersion -source $fs
if ($script:REMOTE_VERSION) { if ($ver) {
$script:SELECTED_SOURCE = $fs $script:SELECTED_SOURCE = $fs
$script:REMOTE_VERSION = $ver
Write-Ok "从 $fs 获取版本成功: v$($script:REMOTE_VERSION)" Write-Ok "从 $fs 获取版本成功: v$($script:REMOTE_VERSION)"
$found = $true
break break
} }
} }
if (-not $script:REMOTE_VERSION) { if (-not $found) {
Write-Warn "使用镜像后仍无法获取版本,请检查 URL 是否正确" Write-Warn "所有来源均无法获取版本"
} }
} }
"0" { exit 1 } "0" { exit 1 }
@@ -1086,7 +1076,6 @@ function Run-QuickMode {
} }
Write-Host "" Write-Host ""
} }
}
Detect-Installed Detect-Installed