tt-help-cli-ycl 1.4.5 → 1.4.7
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 +1 -1
- package/src/cli/tag.js +43 -2
- package/src/lib/browser/cdp.js +19 -0
package/package.json
CHANGED
package/src/cli/tag.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { writeFileSync } from "fs";
|
|
1
|
+
import { writeFileSync, unlinkSync } from "fs";
|
|
2
2
|
import { randomUUID } from "crypto";
|
|
3
3
|
import { execSync } from "child_process";
|
|
4
4
|
import os from "os";
|
|
5
|
+
import path from "path";
|
|
5
6
|
import readline from "readline";
|
|
6
7
|
import { fetchTagData, enrichVideosWithLocation } from "../lib/tag-fetcher.js";
|
|
7
8
|
import { killEdgeProcesses, ensureBrowserReady } from "../lib/browser/cdp.js";
|
|
@@ -66,10 +67,50 @@ function getBrowserMemory(port = null) {
|
|
|
66
67
|
cmd =
|
|
67
68
|
'ps aux | grep "[m]sedge" | awk \'{sum += $6} END {printf "%d", sum/1024}\'';
|
|
68
69
|
}
|
|
70
|
+
} else if (platform === "win32") {
|
|
71
|
+
// Windows: 用 PowerShell 查 msedge 进程内存(WorkingSet64 → MB)
|
|
72
|
+
// 用临时 .ps1 文件避免命令行转义问题
|
|
73
|
+
const ps1Path = path.join(os.tmpdir(), `edge-mem-${Date.now()}.ps1`);
|
|
74
|
+
try {
|
|
75
|
+
let ps1Content;
|
|
76
|
+
if (port) {
|
|
77
|
+
ps1Content =
|
|
78
|
+
`$procs = Get-CimInstance Win32_Process -Filter "Name LIKE 'msedge%'" -ErrorAction SilentlyContinue; ` +
|
|
79
|
+
`$sum = 0; ` +
|
|
80
|
+
`foreach ($p in $procs) { ` +
|
|
81
|
+
` if ($p.CommandLine -and $p.CommandLine -like "*--remote-debugging-port=${port}*") { ` +
|
|
82
|
+
` $sum += $p.WorkingSetSize ` +
|
|
83
|
+
` } ` +
|
|
84
|
+
`}; ` +
|
|
85
|
+
`Write-Output $sum`;
|
|
86
|
+
} else {
|
|
87
|
+
ps1Content =
|
|
88
|
+
`$procs = Get-CimInstance Win32_Process -Filter "Name LIKE 'msedge%'" -ErrorAction SilentlyContinue; ` +
|
|
89
|
+
`$sum = 0; ` +
|
|
90
|
+
`foreach ($p in $procs) { $sum += $p.WorkingSetSize }; ` +
|
|
91
|
+
`Write-Output $sum`;
|
|
92
|
+
}
|
|
93
|
+
writeFileSync(ps1Path, ps1Content);
|
|
94
|
+
cmd = `powershell.exe -NoProfile -ExecutionPolicy Bypass -File "${ps1Path}"`;
|
|
95
|
+
const result = execSync(cmd, { timeout: 5000 }).toString().trim();
|
|
96
|
+
try {
|
|
97
|
+
unlinkSync(ps1Path);
|
|
98
|
+
} catch {}
|
|
99
|
+
// PowerShell 返回 WorkingSetSize(字节),需除以 1048576 得 MB
|
|
100
|
+
const bytes = parseInt(result, 10);
|
|
101
|
+
const mb = bytes > 0 ? Math.round(bytes / 1048576) : 0;
|
|
102
|
+
return mb > 0 ? mb : null;
|
|
103
|
+
} catch {
|
|
104
|
+
try {
|
|
105
|
+
unlinkSync(ps1Path);
|
|
106
|
+
} catch {}
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
69
109
|
} else {
|
|
70
110
|
return null;
|
|
71
111
|
}
|
|
72
|
-
|
|
112
|
+
// macOS/Linux: ps RSS 是 KB,awk 已除以 1024 得 MB
|
|
113
|
+
const result = execSync(cmd, { timeout: 5000 }).toString().trim();
|
|
73
114
|
const mb = parseInt(result, 10);
|
|
74
115
|
return mb > 0 ? mb : null;
|
|
75
116
|
} catch {
|
package/src/lib/browser/cdp.js
CHANGED
|
@@ -97,6 +97,23 @@ function killEdgeProcesses(targetDir, port) {
|
|
|
97
97
|
} else {
|
|
98
98
|
command = "true";
|
|
99
99
|
}
|
|
100
|
+
} else if (port) {
|
|
101
|
+
// 仅按端口筛选,不误杀其他端口的 Edge 实例
|
|
102
|
+
let pids = "";
|
|
103
|
+
try {
|
|
104
|
+
pids = execSync(
|
|
105
|
+
`ps aux | grep "[M]icrosoft Edge" | grep -v "Helper\\|crashpad" | grep "remote-debugging-port=${port}" | awk '{print $2}'`,
|
|
106
|
+
)
|
|
107
|
+
.toString()
|
|
108
|
+
.trim();
|
|
109
|
+
} catch (e) {
|
|
110
|
+
pids = "";
|
|
111
|
+
}
|
|
112
|
+
if (pids) {
|
|
113
|
+
command = `kill -9 ${pids} 2>/dev/null; rm -f ~/Library/Caches/Microsoft\\ Edge/Singleton*; true`;
|
|
114
|
+
} else {
|
|
115
|
+
command = "true";
|
|
116
|
+
}
|
|
100
117
|
} else {
|
|
101
118
|
command =
|
|
102
119
|
'killall -9 "Microsoft Edge" 2>/dev/null; rm -f ~/Library/Caches/Microsoft\\ Edge/Singleton*; true';
|
|
@@ -143,6 +160,8 @@ function killEdgeProcesses(targetDir, port) {
|
|
|
143
160
|
if (targetDir) {
|
|
144
161
|
const escapedDir = targetDir.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
145
162
|
command = `ps aux | grep msedge | grep -v Helper | grep -E -- '--user-data-dir=${escapedDir}($|[^A-Za-z0-9_])' | awk '{print $2}' | xargs -r kill -9 2>/dev/null; true`;
|
|
163
|
+
} else if (port) {
|
|
164
|
+
command = `ps aux | grep msedge | grep -v Helper | grep "remote-debugging-port=${port}" | awk '{print $2}' | xargs -r kill -9 2>/dev/null; true`;
|
|
146
165
|
} else {
|
|
147
166
|
command = "pkill -9 -f msedge 2>/dev/null; true";
|
|
148
167
|
}
|