feat: prefer remote MCP OAuth installation
This commit is contained in:
@@ -23,17 +23,30 @@ function Get-DingSha256([string] $dingPath) {
|
||||
|
||||
function Save-DingDownload([string[]] $dingUrls, [string] $dingTarget, [string] $dingExpectedSha256) {
|
||||
$dingLastError = $null
|
||||
$dingCurl = Get-Command curl.exe -ErrorAction SilentlyContinue
|
||||
foreach ($dingUrl in $dingUrls) {
|
||||
Write-DingProgress "正在下载并校验:$dingUrl"
|
||||
try {
|
||||
if (Test-Path -LiteralPath $dingTarget) { Remove-Item -LiteralPath $dingTarget -Force }
|
||||
Invoke-WebRequest -UseBasicParsing -Uri $dingUrl -OutFile $dingTarget -TimeoutSec 300
|
||||
if ($dingCurl) {
|
||||
$dingCurlHttp = & $dingCurl.Source --fail --location --silent --show-error --connect-timeout 10 --max-time 90 --speed-time 20 --speed-limit 1024 --write-out "%{http_code}" --output $dingTarget $dingUrl
|
||||
$dingCurlExit = $LASTEXITCODE
|
||||
if ($dingCurlExit -ne 0) {
|
||||
if ($dingCurlHttp -match '^[1-5][0-9][0-9]$' -and $dingCurlHttp -ne '000') { throw "HTTP $dingCurlHttp" }
|
||||
throw "curl.exe 退出码 $dingCurlExit"
|
||||
}
|
||||
} else {
|
||||
Invoke-WebRequest -UseBasicParsing -Uri $dingUrl -OutFile $dingTarget -TimeoutSec 90
|
||||
}
|
||||
} catch {
|
||||
$dingLastError = $_.Exception.Message
|
||||
$dingStatusCode = $null
|
||||
if ($_.Exception.Response -and $_.Exception.Response.StatusCode) {
|
||||
try { $dingStatusCode = [int]$_.Exception.Response.StatusCode } catch { $dingStatusCode = $null }
|
||||
}
|
||||
if ($null -eq $dingStatusCode -and $dingLastError -match 'HTTP ([0-9][0-9][0-9])') {
|
||||
$dingStatusCode = [int]$Matches[1]
|
||||
}
|
||||
if ($null -eq $dingStatusCode -or $dingStatusCode -eq 404) { continue }
|
||||
throw "下载失败且不允许换源(HTTP $dingStatusCode):$dingUrl;$dingLastError"
|
||||
}
|
||||
@@ -49,7 +62,7 @@ function Save-DingDownload([string[]] $dingUrls, [string] $dingTarget, [string]
|
||||
function Test-DingNode([string] $dingNodePath, [bool] $dingRequireAdjacentNpm) {
|
||||
if (-not $dingNodePath -or -not (Test-Path -LiteralPath $dingNodePath -PathType Leaf)) { return $false }
|
||||
try {
|
||||
& $dingNodePath -e 'const [a,b]=process.versions.node.split(".").map(Number);process.exit(a>22||(a===22&&b>=13)?0:1)'
|
||||
& $dingNodePath -e "const [a,b]=process.versions.node.split('.').map(Number);process.exit(a>22||(a===22&&b>=13)?0:1)"
|
||||
if ($LASTEXITCODE -ne 0) { return $false }
|
||||
if ($dingRequireAdjacentNpm) {
|
||||
$dingNpmCli = Join-Path (Split-Path -Parent $dingNodePath) "node_modules\npm\bin\npm-cli.js"
|
||||
@@ -126,7 +139,7 @@ try {
|
||||
$dingProxyConfigured = $env:HTTPS_PROXY -or $env:HTTP_PROXY -or $env:ALL_PROXY
|
||||
$dingProxyAlreadyEnabled = ($env:NODE_OPTIONS -match '(^|\s)--use-env-proxy($|\s)') -or ($env:NODE_USE_ENV_PROXY -match '^(1|true)$')
|
||||
if ($dingProxyConfigured -and -not $dingProxyAlreadyEnabled) {
|
||||
& $dingNodePath -e 'process.exit(process.allowedNodeEnvironmentFlags.has("--use-env-proxy") ? 0 : 1)'
|
||||
& $dingNodePath -e "process.exit(process.allowedNodeEnvironmentFlags.has('--use-env-proxy') ? 0 : 1)"
|
||||
if ($LASTEXITCODE -eq 0) { $dingNodeProxyArgs = @("--use-env-proxy") }
|
||||
}
|
||||
$dingInstallOutput = & $dingNodePath @dingNodeProxyArgs @dingInstallerArgs
|
||||
|
||||
Reference in New Issue
Block a user