feat: offer mirror config choices interactively when version fetch fails in quick mode

This commit is contained in:
i
2026-06-02 00:19:51 +08:00
parent 305d07e14b
commit 61d75a730c
+59 -2
View File
@@ -1162,8 +1162,65 @@ function Run-QuickMode {
$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-Err "无法获取远程版本" Write-Warn "无法从 $($script:SELECTED_SOURCE) 获取远程版本"
exit 1 # 尝试备用来源
$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) {
Write-Err "无法从任何来源获取远程版本"
Write-Host ""
Write-Info "可能原因: 网络连接问题 / npm registry 或 GitHub API 访问受限"
Write-Host ""
Write-Host "是否配置镜像以继续安装?" -ForegroundColor Yellow
Write-Host " 1) 配置 npm 镜像 (如 https://registry.npmmirror.com)"
Write-Host " 2) 配置 GitHub 镜像 (如 https://ghproxy.com)"
Write-Host " 0) 退出"
Write-Host ""
$choice = Read-Host "请输入选项 [0-2]"
switch ($choice) {
"1" {
$reg = Read-Host "请输入 npm registry URL (Enter 使用默认 https://registry.npmmirror.com)"
$script:NPM_REGISTRY = if ($reg) { $reg } else { "https://registry.npmmirror.com" }
Write-Ok "npm registry 已设置为: $script:NPM_REGISTRY"
$script:SELECTED_SOURCE = "npm"
$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)"
$script:GITHUB_MIRROR = if ($mirror) { $mirror } else { "https://ghproxy.com" }
Write-Ok "GitHub 镜像已设置为: $script:GITHUB_MIRROR"
$allSources = @("github-official", "github-fork")
foreach ($fs in $allSources) {
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
}
}
if (-not $script:REMOTE_VERSION) {
Write-Warn "使用镜像后仍无法获取版本,请检查 URL 是否正确"
}
}
"0" { exit 1 }
default { Write-Warn "无效选项,请重新输入" }
}
Write-Host ""
}
} }
Detect-Installed Detect-Installed