tt-help-cli-ycl 1.4.59 → 1.4.61
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/package.json
CHANGED
|
@@ -83,9 +83,9 @@ function getOnlineClients() {
|
|
|
83
83
|
|
|
84
84
|
function normalizeCmd(c) {
|
|
85
85
|
if (typeof c === "string")
|
|
86
|
-
return { cmd: c, enabled: true, maxUptimeSeconds: 0, maxMemoryMB: 0 };
|
|
86
|
+
return { cmd: c.replace(/^[▶\n\r\s]+/, "").trim(), enabled: true, maxUptimeSeconds: 0, maxMemoryMB: 0 };
|
|
87
87
|
return {
|
|
88
|
-
cmd: c.cmd || "",
|
|
88
|
+
cmd: (c.cmd || "").replace(/^[▶\n\r\s]+/, "").trim(),
|
|
89
89
|
enabled: c.enabled !== false,
|
|
90
90
|
maxUptimeSeconds: c.maxUptimeSeconds || 0,
|
|
91
91
|
maxMemoryMB: c.maxMemoryMB || 0,
|
|
@@ -108,9 +108,14 @@ function getClientCommands(userId) {
|
|
|
108
108
|
|
|
109
109
|
function setClientCommands(userId, commands) {
|
|
110
110
|
if (!Array.isArray(commands)) return;
|
|
111
|
+
// 清洗每个命令中的非法前缀
|
|
112
|
+
const cleaned = commands.map((c) => {
|
|
113
|
+
if (typeof c === "string") return c.replace(/^[▶\n\r\s]+/, "").trim();
|
|
114
|
+
return { ...c, cmd: (c.cmd || "").replace(/^[▶\n\r\s]+/, "").trim() };
|
|
115
|
+
});
|
|
111
116
|
const cfg = loadConfig();
|
|
112
117
|
if (!cfg.clientCommands) cfg.clientCommands = {};
|
|
113
|
-
cfg.clientCommands[userId] =
|
|
118
|
+
cfg.clientCommands[userId] = cleaned;
|
|
114
119
|
saveConfig(cfg);
|
|
115
120
|
}
|
|
116
121
|
|
|
@@ -11,13 +11,8 @@
|
|
|
11
11
|
|
|
12
12
|
import { spawn, execSync } from "child_process";
|
|
13
13
|
import { EventEmitter } from "events";
|
|
14
|
-
import os from "os";
|
|
15
14
|
|
|
16
15
|
const MAX_RESTART = 3;
|
|
17
|
-
const SHELL =
|
|
18
|
-
os.platform() === "win32"
|
|
19
|
-
? { cmd: process.env.COMSPEC || "cmd.exe", flag: "/c" }
|
|
20
|
-
: { cmd: "sh", flag: "-c" };
|
|
21
16
|
|
|
22
17
|
function getProcessStats(pid) {
|
|
23
18
|
try {
|
|
@@ -65,16 +60,17 @@ export class ProcessManager extends EventEmitter {
|
|
|
65
60
|
let child;
|
|
66
61
|
const startTime = Date.now();
|
|
67
62
|
try {
|
|
68
|
-
// 有显式 args 则直接 spawn,否则用
|
|
63
|
+
// 有显式 args 则直接 spawn,否则用 shell 模式传递完整命令行(跨平台兼容)
|
|
69
64
|
if (args.length > 0) {
|
|
70
65
|
child = spawn(command, args, {
|
|
71
66
|
stdio: ["ignore", "pipe", "pipe"],
|
|
72
67
|
detached: false,
|
|
73
68
|
});
|
|
74
69
|
} else {
|
|
75
|
-
child = spawn(
|
|
70
|
+
child = spawn(command, {
|
|
76
71
|
stdio: ["ignore", "pipe", "pipe"],
|
|
77
72
|
detached: false,
|
|
73
|
+
shell: true,
|
|
78
74
|
});
|
|
79
75
|
}
|
|
80
76
|
} catch (e) {
|
|
@@ -227,7 +223,8 @@ export class ProcessManager extends EventEmitter {
|
|
|
227
223
|
.map((c) => {
|
|
228
224
|
if (typeof c === "string")
|
|
229
225
|
c = { cmd: c, maxUptimeSeconds: 0, maxMemoryMB: 0 };
|
|
230
|
-
|
|
226
|
+
// 清洗:去除可能混入的控制字符、状态图标等
|
|
227
|
+
const cmdLine = (c.cmd || "").replace(/^[▶\n\r\s]+/, "").trim();
|
|
231
228
|
if (!cmdLine) return null;
|
|
232
229
|
const id =
|
|
233
230
|
cmdLine.length > 60 ? cmdLine.substring(0, 60) + "..." : cmdLine;
|