@wendongfly/myhi 1.3.103 → 1.3.104

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/myhi.js CHANGED
@@ -11,6 +11,7 @@ const __dirname = dirname(__filename);
11
11
  // 解析 -p / --port 参数
12
12
  const args = process.argv.slice(2);
13
13
  let cmd = null;
14
+ let httpOnlyFlag = null; // null=不改;true=切 HTTP-only;false=切回 HTTPS
14
15
  for (let i = 0; i < args.length; i++) {
15
16
  if ((args[i] === '-p' || args[i] === '--port') && args[i + 1]) {
16
17
  process.env.PORT = args[i + 1];
@@ -18,6 +19,10 @@ for (let i = 0; i < args.length; i++) {
18
19
  } else if (args[i].startsWith('--port=')) {
19
20
  process.env.PORT = args[i].split('=')[1];
20
21
  args.splice(i, 1); i--;
22
+ } else if (args[i] === '--http' || args[i] === '--no-https') {
23
+ httpOnlyFlag = true; args.splice(i, 1); i--;
24
+ } else if (args[i] === '--https') {
25
+ httpOnlyFlag = false; args.splice(i, 1); i--;
21
26
  } else if (!cmd && !args[i].startsWith('-')) {
22
27
  cmd = args[i];
23
28
  }
@@ -39,6 +44,24 @@ if (cmd === '--version' || cmd === '-v' || cmd === 'version') {
39
44
  const configDir = join(homedir(), '.myhi');
40
45
  const pidFile = join(configDir, 'daemon.pid');
41
46
  const logFile = join(configDir, 'daemon.log');
47
+ const configFile = join(configDir, 'config.json');
48
+
49
+ // --http / --https:持久化 HTTP-only 开关到 config.json,server 启动时读取(任何重启都保留,
50
+ // 不依赖环境变量从 daemon 往下传)。设完若没显式命令,就自动 restart 让它立刻生效。
51
+ if (httpOnlyFlag !== null) {
52
+ try {
53
+ mkdirSync(configDir, { recursive: true });
54
+ let cfg = {};
55
+ try { cfg = JSON.parse(readFileSync(configFile, 'utf8')); } catch {}
56
+ cfg.httpOnly = httpOnlyFlag;
57
+ writeFileSync(configFile, JSON.stringify(cfg, null, 2));
58
+ console.log(`[myhi] 已切换为 ${httpOnlyFlag ? 'HTTP(无 TLS,麦克风/摄像头等在非 localhost 会受限)' : 'HTTPS'} 模式`);
59
+ } catch (e) {
60
+ console.error('[myhi] 写入 config.json 失败:', e.message);
61
+ process.exit(1);
62
+ }
63
+ if (!cmd) cmd = 'restart'; // 无显式命令 → 切完直接重启使其生效
64
+ }
42
65
 
43
66
  // ── 工具函数 ──────────────────────────────────────────────
44
67
 
@@ -585,6 +608,8 @@ myhi — 基于 Web 的终端共享工具 (${platform})
585
608
  myhi start 前台启动服务器
586
609
  myhi -p <port> 指定监听端口(默认 12300)
587
610
  myhi -d 后台启动(日志写入 ${configPath}daemon.log)
611
+ myhi --http 切为纯 HTTP(无 TLS)并重启,持久生效
612
+ myhi --https 切回 HTTPS(默认)并重启
588
613
  myhi stop 停止后台服务器
589
614
  myhi restart 重启后台服务器
590
615
  myhi status 查看运行状态