From 581ba6aa00bba85fa8ab1989779f8341e8ee798e Mon Sep 17 00:00:00 2001 From: luke-win Date: Tue, 11 Aug 2026 12:22:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20install.ps1=20?= =?UTF-8?q?=E5=92=8C=20clash.ps1=20=E5=85=B1=204=20=E4=B8=AA=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- clash.ps1 | 21 +++++++++++++++++---- install.ps1 | 9 ++++++--- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/clash.ps1 b/clash.ps1 index 641c4c4..4a4754e 100644 --- a/clash.ps1 +++ b/clash.ps1 @@ -444,10 +444,21 @@ function Invoke-CmdReload { Write-Host -NoNewline " 热重载配置 ... " try { # mihomo API 开启 secret 时必须带 Bearer 鉴权,否则 PUT /configs 会 401 + # BUGFIX: 旧逻辑只处理双引号和裸值,漏了单引号(secret: 'xxx') + # 且 fallback 正则会连引号一起捕获导致鉴权失败 + # 现在三级 fallback:双引号 → 单引号 → 裸值,每级精确匹配不吞引号 $headers = @{} if (Test-Path $Cfg) { + # 匹配双引号: secret: "mysecret" $secLine = Select-String -Path $Cfg -Pattern '^\s*secret:\s*"([^"]+)"' | Select-Object -First 1 - if (-not $secLine) { $secLine = Select-String -Path $Cfg -Pattern '^\s*secret:\s*([^\s#]+)' | Select-Object -First 1 } + if (-not $secLine) { + # 匹配单引号: secret: 'mysecret' + $secLine = Select-String -Path $Cfg -Pattern "^\s*secret:\s*'([^']+)'" | Select-Object -First 1 + } + if (-not $secLine) { + # 匹配裸值: secret: mysecret + $secLine = Select-String -Path $Cfg -Pattern '^\s*secret:\s*([^\s#]+)' | Select-Object -First 1 + } if ($secLine) { $headers['Authorization'] = "Bearer $($secLine.Matches[0].Groups[1].Value)" } } $body = @{ path = $Cfg } | ConvertTo-Json -Compress @@ -503,9 +514,11 @@ function Invoke-CmdLink { } } Write-Host "" - $input = Read-Host " 请输入 YAML 文件路径 (Enter 取消)" - if (-not $input) { W-Dim "已取消"; return } - $Src = $input.Trim().Trim('"') + # BUGFIX: $input 是 PowerShell 自动变量(包含管道输入),不能当普通变量使用 + # 旧代码用 $input 存储用户输入会导致意外行为,改为 $inputPath + $inputPath = Read-Host " 请输入 YAML 文件路径 (Enter 取消)" + if (-not $inputPath) { W-Dim "已取消"; return } + $Src = $inputPath.Trim().Trim('"') } if (-not (Test-Path $Src)) { diff --git a/install.ps1 b/install.ps1 index 3e0d82d..73983f5 100644 --- a/install.ps1 +++ b/install.ps1 @@ -110,7 +110,7 @@ if ($needDownload) { } catch { W-Fail "下载失败: $_" W-Note "手动下载: $mihomoUrl" - W-Note "解压 mihomo.exe 到: $InstallDir" + W-Note "解压 mihomo 可执行文件到: $InstallDir" # BUGFIX: 提示文案从 "mihomo.exe" 改为 "mihomo 可执行文件",因为 zip 内文件名不是 mihomo.exe exit 1 } @@ -118,14 +118,17 @@ if ($needDownload) { W-Step "解压中 ..." Expand-Archive -Path $mihomoZip -DestinationPath $tempDir.FullName -Force - # 找到 mihomo 可执行文件并复制(官方 zip 内名为 mihomo-windows-amd64-v1.exe) + # 找到 mihomo 可执行文件并复制 + # BUGFIX: 官方 zip 内二进制名为 mihomo-windows-amd64-v1.exe,不是 mihomo.exe + # 旧逻辑用 -Filter "mihomo.exe" 精确匹配会找不到,改用 *.exe 通配 + like "mihomo*" 模糊匹配 + # 这样对 amd64(v1/compatible)、arm64 等所有架构变体都有效 $extracted = Get-ChildItem $tempDir.FullName -Recurse -Filter "*.exe" | Where-Object { $_.Name -like "mihomo*" } | Select-Object -First 1 if ($extracted) { Copy-Item $extracted.FullName $mihomoExe -Force W-Done "mihomo.exe 已安装" } else { - W-Fail "未在压缩包中找到 mihomo.exe" + W-Fail "未在压缩包中找到 mihomo 可执行文件" # BUGFIX: 同上,提示文案从 "mihomo.exe" 改为 "mihomo 可执行文件" exit 1 }