Files
mnote/services/mineru/start.ps1
T
2025-11-23 10:55:04 +08:00

35 lines
1.2 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
[CmdletBinding()]
param(
[string]$ListenHost,
[int]$ListenPort,
[string]$ModulePath
)
$ErrorActionPreference = "Stop"
$resolvedHost = if ($PSBoundParameters.ContainsKey("ListenHost")) { $ListenHost } elseif ($env:MINERU_HOST) { $env:MINERU_HOST } else { "127.0.0.1" }
$resolvedPort = if ($PSBoundParameters.ContainsKey("ListenPort")) { $ListenPort } elseif ($env:MINERU_PORT) { [int]$env:MINERU_PORT } else { 18888 }
$resolvedModule = if ($PSBoundParameters.ContainsKey("ModulePath")) { $ModulePath } elseif ($env:MINERU_MODULE) { $env:MINERU_MODULE } else { "mineru.cli.fast_api:app" }
$venvDir = Join-Path $PSScriptRoot ".venv"
$pythonBin = Join-Path $venvDir "Scripts" "python.exe"
if (-not (Test-Path $pythonBin)) {
throw "未找到虚拟环境 Python$pythonBin,请先执行 setup.ps1"
}
$srcDir = Join-Path $PSScriptRoot "src"
if (-not (Test-Path $srcDir)) {
throw "未找到 MinerU 源码:$srcDir,请先执行 setup.ps1"
}
Push-Location $srcDir
try {
$env:PYTHONPATH = $srcDir
$cmd = "$pythonBin -m uvicorn $resolvedModule --host $resolvedHost --port $resolvedPort"
Write-Host ">>> 启动 MinerU$cmd"
& $pythonBin -m uvicorn $resolvedModule --host $resolvedHost --port $resolvedPort
}
finally {
Pop-Location
}