From 551ff9c4c99f13addd3dbfa7db0ac475231bae0f Mon Sep 17 00:00:00 2001 From: lukeopen Date: Tue, 11 Aug 2026 09:53:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20Windows=20=E9=83=A8?= =?UTF-8?q?=E7=BD=B2=20install.ps1=20=E8=A7=A3=E5=8E=8B=20bug=20+=20reload?= =?UTF-8?q?=20=E9=89=B4=E6=9D=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - install.ps1: 官方 zip 内 exe 名为 mihomo-windows-amd64-v1.exe, 改为匹配 *.exe + mihomo* 前缀,不再硬找 mihomo.exe - clash.ps1: 热重载 PUT /configs 补上 secret Bearer 鉴权, 避免开启 secret 后 reload 一直 401 退化成重启 --- clash.ps1 | 9 ++++++++- install.ps1 | 5 +++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/clash.ps1 b/clash.ps1 index bd8f5ea..641c4c4 100644 --- a/clash.ps1 +++ b/clash.ps1 @@ -443,9 +443,16 @@ function Invoke-CmdReload { Write-Host -NoNewline " 热重载配置 ... " try { + # mihomo API 开启 secret 时必须带 Bearer 鉴权,否则 PUT /configs 会 401 + $headers = @{} + if (Test-Path $Cfg) { + $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 ($secLine) { $headers['Authorization'] = "Bearer $($secLine.Matches[0].Groups[1].Value)" } + } $body = @{ path = $Cfg } | ConvertTo-Json -Compress $uri = "http://127.0.0.1:$ApiPort/configs" - $resp = Invoke-WebRequest -Method PUT -Uri $uri -ContentType "application/json" -Body $body -UseBasicParsing -ErrorAction Stop + $resp = Invoke-WebRequest -Method PUT -Uri $uri -ContentType "application/json" -Body $body -Headers $headers -UseBasicParsing -ErrorAction Stop W-Ok "成功" } catch { W-Err "API 不可达,尝试重启..." diff --git a/install.ps1 b/install.ps1 index 2ed93fd..3e0d82d 100644 --- a/install.ps1 +++ b/install.ps1 @@ -118,8 +118,9 @@ if ($needDownload) { W-Step "解压中 ..." Expand-Archive -Path $mihomoZip -DestinationPath $tempDir.FullName -Force - # 找到 mihomo.exe 并复制 - $extracted = Get-ChildItem $tempDir.FullName -Recurse -Filter "mihomo.exe" | Select-Object -First 1 + # 找到 mihomo 可执行文件并复制(官方 zip 内名为 mihomo-windows-amd64-v1.exe) + $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 已安装"