fix: 修复 install.ps1 和 clash.ps1 共 4 个 bug
This commit is contained in:
@@ -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)) {
|
||||
|
||||
+6
-3
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user