fix: 修复 Windows 部署 install.ps1 解压 bug + reload 鉴权
- install.ps1: 官方 zip 内 exe 名为 mihomo-windows-amd64-v1.exe, 改为匹配 *.exe + mihomo* 前缀,不再硬找 mihomo.exe - clash.ps1: 热重载 PUT /configs 补上 secret Bearer 鉴权, 避免开启 secret 后 reload 一直 401 退化成重启
This commit is contained in:
@@ -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 不可达,尝试重启..."
|
||||
|
||||
+3
-2
@@ -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 已安装"
|
||||
|
||||
Reference in New Issue
Block a user