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 已安装"