fix: 修复 install.ps1 和 clash.ps1 共 4 个 bug

This commit is contained in:
luke-win
2026-08-11 12:22:14 +08:00
parent 551ff9c4c9
commit 581ba6aa00
2 changed files with 23 additions and 7 deletions
+17 -4
View File
@@ -444,10 +444,21 @@ function Invoke-CmdReload {
Write-Host -NoNewline " 热重载配置 ... " Write-Host -NoNewline " 热重载配置 ... "
try { try {
# mihomo API 开启 secret 时必须带 Bearer 鉴权,否则 PUT /configs 会 401 # mihomo API 开启 secret 时必须带 Bearer 鉴权,否则 PUT /configs 会 401
# BUGFIX: 旧逻辑只处理双引号和裸值,漏了单引号(secret: 'xxx'
# 且 fallback 正则会连引号一起捕获导致鉴权失败
# 现在三级 fallback:双引号 → 单引号 → 裸值,每级精确匹配不吞引号
$headers = @{} $headers = @{}
if (Test-Path $Cfg) { if (Test-Path $Cfg) {
# 匹配双引号: secret: "mysecret"
$secLine = Select-String -Path $Cfg -Pattern '^\s*secret:\s*"([^"]+)"' | Select-Object -First 1 $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)" } if ($secLine) { $headers['Authorization'] = "Bearer $($secLine.Matches[0].Groups[1].Value)" }
} }
$body = @{ path = $Cfg } | ConvertTo-Json -Compress $body = @{ path = $Cfg } | ConvertTo-Json -Compress
@@ -503,9 +514,11 @@ function Invoke-CmdLink {
} }
} }
Write-Host "" Write-Host ""
$input = Read-Host " 请输入 YAML 文件路径 (Enter 取消)" # BUGFIX: $input 是 PowerShell 自动变量(包含管道输入),不能当普通变量使用
if (-not $input) { W-Dim "已取消"; return } # 旧代码用 $input 存储用户输入会导致意外行为,改为 $inputPath
$Src = $input.Trim().Trim('"') $inputPath = Read-Host " 请输入 YAML 文件路径 (Enter 取消)"
if (-not $inputPath) { W-Dim "已取消"; return }
$Src = $inputPath.Trim().Trim('"')
} }
if (-not (Test-Path $Src)) { if (-not (Test-Path $Src)) {
+6 -3
View File
@@ -110,7 +110,7 @@ if ($needDownload) {
} catch { } catch {
W-Fail "下载失败: $_" W-Fail "下载失败: $_"
W-Note "手动下载: $mihomoUrl" W-Note "手动下载: $mihomoUrl"
W-Note "解压 mihomo.exe 到: $InstallDir" W-Note "解压 mihomo 可执行文件到: $InstallDir" # BUGFIX: 提示文案从 "mihomo.exe" 改为 "mihomo 可执行文件",因为 zip 内文件名不是 mihomo.exe
exit 1 exit 1
} }
@@ -118,14 +118,17 @@ if ($needDownload) {
W-Step "解压中 ..." W-Step "解压中 ..."
Expand-Archive -Path $mihomoZip -DestinationPath $tempDir.FullName -Force 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" | $extracted = Get-ChildItem $tempDir.FullName -Recurse -Filter "*.exe" |
Where-Object { $_.Name -like "mihomo*" } | Select-Object -First 1 Where-Object { $_.Name -like "mihomo*" } | Select-Object -First 1
if ($extracted) { if ($extracted) {
Copy-Item $extracted.FullName $mihomoExe -Force Copy-Item $extracted.FullName $mihomoExe -Force
W-Done "mihomo.exe 已安装" W-Done "mihomo.exe 已安装"
} else { } else {
W-Fail "未在压缩包中找到 mihomo.exe" W-Fail "未在压缩包中找到 mihomo 可执行文件" # BUGFIX: 同上,提示文案从 "mihomo.exe" 改为 "mihomo 可执行文件"
exit 1 exit 1
} }