tt-help-cli-ycl 1.4.60 → 1.4.62
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
|
|
|
@@ -13,14 +13,31 @@ import { spawn, execSync } from "child_process";
|
|
|
13
13
|
import { EventEmitter } from "events";
|
|
14
14
|
|
|
15
15
|
const MAX_RESTART = 3;
|
|
16
|
+
const IS_WIN = process.platform === "win32";
|
|
16
17
|
|
|
17
18
|
function getProcessStats(pid) {
|
|
18
19
|
try {
|
|
19
|
-
const
|
|
20
|
+
const cmd = IS_WIN
|
|
21
|
+
? `tasklist /FI "PID eq ${pid}" /FO CSV /NH`
|
|
22
|
+
: `ps -p ${pid} -o rss=,etime=`;
|
|
23
|
+
const stdout = execSync(cmd, {
|
|
20
24
|
encoding: "utf-8",
|
|
21
25
|
timeout: 3000,
|
|
26
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
22
27
|
}).trim();
|
|
23
28
|
if (!stdout) return null;
|
|
29
|
+
|
|
30
|
+
if (IS_WIN) {
|
|
31
|
+
// tasklist CSV: "name.exe","pid","session","session#","mem usage"
|
|
32
|
+
const cols = stdout.split(",");
|
|
33
|
+
const memStr = (cols[4] || "").replace(/[^0-9.]/g, "");
|
|
34
|
+
const memKB = parseInt(memStr, 10);
|
|
35
|
+
return {
|
|
36
|
+
memoryMB: isNaN(memKB) ? 0 : Math.round((memKB / 1024) * 10) / 10,
|
|
37
|
+
elapsed: "?",
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
24
41
|
const parts = stdout.split(/\s+/);
|
|
25
42
|
const rssKB = parseInt(parts[0], 10);
|
|
26
43
|
const elapsed = parts.slice(1).join(" ") || "0";
|
|
@@ -223,7 +240,8 @@ export class ProcessManager extends EventEmitter {
|
|
|
223
240
|
.map((c) => {
|
|
224
241
|
if (typeof c === "string")
|
|
225
242
|
c = { cmd: c, maxUptimeSeconds: 0, maxMemoryMB: 0 };
|
|
226
|
-
|
|
243
|
+
// 清洗:去除可能混入的控制字符、状态图标等
|
|
244
|
+
const cmdLine = (c.cmd || "").replace(/^[▶\n\r\s]+/, "").trim();
|
|
227
245
|
if (!cmdLine) return null;
|
|
228
246
|
const id =
|
|
229
247
|
cmdLine.length > 60 ? cmdLine.substring(0, 60) + "..." : cmdLine;
|