MCPcopy Create free account
hub / github.com/VirtualHotBar/NetMount / startOpenlist

Function startOpenlist

src/utils/openlist/process.ts:17–88  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15import { parseExtraCliArgs } from '../cliArgs'
16
17async function startOpenlist() {
18 //设置默认临时(缓存)目录
19 openlistInfo.openlistConfig.temp_dir = formatPath(
20 nmConfig.settings.path.cacheDir + '/openlist/',
21 osInfo.osType === 'windows'
22 )
23
24 //自动分配端口
25 openlistInfo.openlistConfig.scheme!.http_port = (await getAvailablePorts(2))[1]!
26
27 openlistInfo.endpoint.url =
28 'http://localhost:' + (openlistInfo.openlistConfig.scheme?.http_port || 5573)
29 console.log('OpenList will start on port:', openlistInfo.openlistConfig.scheme?.http_port)
30 console.log('OpenList endpoint URL:', openlistInfo.endpoint.url)
31
32 // 先保存配置到文件
33 await modifyOpenlistConfig()
34
35 // 无条件重置 admin 密码,避免升级/迁移导致的密码不一致
36 try {
37 await setOpenlistPass(nmConfig.framework.openlist.password)
38 } catch (e) {
39 // 预启动阶段重置失败(例如 CLI 不可用),继续启动,稍后再尝试修复
40 console.warn('OpenList pre-start password reset failed, will retry after server starts:', e)
41 }
42
43 const args: string[] = [
44 'server',
45 ...addParams(),
46 ...parseExtraCliArgs(nmConfig.framework.openlist.extraArgs),
47 ]
48 console.log('OpenList start args:', args)
49
50 // 使用 Rust 端启动 sidecar,确保由主进程创建
51 // 传入数据目录作为工作目录,确保 openlist 能正确找到数据库文件
52 const dataDir = openlistDataDir()
53 let pid: number
54 try {
55 pid = await startSidecarAndWait({
56 binary: 'binaries/openlist',
57 name: 'openlist',
58 args,
59 readyCheck: openlist_api_ping,
60 timeoutMs: 30_000,
61 cwd: dataDir,
62 })
63 } catch (e) {
64 console.error('Failed to spawn OpenList:', e)
65 throw new Error(`Failed to spawn OpenList: ${e}`)
66 }
67
68 openlistInfo.process.child = { pid } as Child
69 openlistInfo.process.log = '' // 初始化日志
70 openlistInfo.process.logFile = openlistLogFile()
71 console.log('openlist spawned from Rust, PID:', pid)
72
73 // 服务启动后再获取 token;若失败则尝试重置密码后重试一次
74 try {

Callers 1

initFunction · 0.90

Calls 11

formatPathFunction · 0.90
getAvailablePortsFunction · 0.90
modifyOpenlistConfigFunction · 0.90
setOpenlistPassFunction · 0.90
addParamsFunction · 0.90
parseExtraCliArgsFunction · 0.90
startSidecarAndWaitFunction · 0.90
openlistLogFileFunction · 0.90
getOpenlistTokenFunction · 0.90
openlistDataDirFunction · 0.85

Tested by

no test coverage detected