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

Function startRclone

src/utils/rclone/process.ts:13–66  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11import { parseExtraCliArgs } from '../cliArgs'
12
13async function startRclone() {
14 if (rcloneInfo.process.child) {
15 await stopRclone()
16 }
17
18 //设置缓存目录
19 rcloneInfo.localArgs.path.tempDir = formatPath(
20 nmConfig.settings.path.cacheDir + '/rclone/',
21 osInfo.osType === 'windows'
22 )
23
24 //自动分配端口
25 rcloneInfo.endpoint.localhost.port = (await getAvailablePorts(2))[1]!
26
27 rcloneInfo.endpoint.url = 'http://127.0.0.1:' + rcloneInfo.endpoint.localhost.port.toString()
28
29 // 确保日志目录存在(用于“设置-组件-日志”查看)
30 const logDir = netmountLogDir()
31 const logFile = rcloneLogFile()
32 try {
33 await invoke('fs_make_dir', { path: logDir })
34 } catch {
35 // ignore
36 }
37 rcloneInfo.process.logFile = logFile
38
39 const args: string[] = [
40 'rcd',
41 `--rc-addr=:${rcloneInfo.endpoint.localhost.port.toString()}`,
42 `--rc-user=${nmConfig.framework.rclone.user}`,
43 `--rc-pass=${nmConfig.framework.rclone.password}`,
44 '--rc-allow-origin=' + window.location.origin || '*',
45 `--config=${rcloneConfigFile()}`,
46 '--cache-dir=' + rcloneInfo.localArgs.path.tempDir,
47 `--log-file=${logFile}`,
48 '--log-level=INFO',
49 ]
50
51 if (nmConfig.framework.rclone.user === '') {
52 args.push('--rc-no-auth')
53 }
54 args.push(...parseExtraCliArgs(nmConfig.framework.rclone.extraArgs))
55
56 // 使用 Rust 端启动 sidecar,确保由主进程创建
57 const pid = await startSidecarAndWait({
58 binary: 'binaries/rclone',
59 name: 'rclone',
60 args,
61 readyCheck: rclone_api_noop,
62 initialDelayMs: 1000,
63 })
64 rcloneInfo.process.child = { pid } as Child
65 console.log('rclone spawned from Rust, PID:', pid)
66}
67
68async function stopRclone() {
69 await delStorage(openlistInfo.markInRclone)

Callers 1

initFunction · 0.90

Calls 8

formatPathFunction · 0.90
getAvailablePortsFunction · 0.90
netmountLogDirFunction · 0.90
rcloneLogFileFunction · 0.90
rcloneConfigFileFunction · 0.90
parseExtraCliArgsFunction · 0.90
startSidecarAndWaitFunction · 0.90
stopRcloneFunction · 0.85

Tested by

no test coverage detected