tt-help-cli-ycl 1.4.46 → 1.4.47

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tt-help-cli-ycl",
3
- "version": "1.4.46",
3
+ "version": "1.4.47",
4
4
  "description": "TikTok user & video data scraper - extract ttSeller, verified, locationCreated from HTML source",
5
5
  "type": "module",
6
6
  "bin": {
@@ -84,6 +84,9 @@ function extractJsonByKey(html, keyPattern) {
84
84
  /**
85
85
  * Windows: 后台服务的 Playwright 浏览器在 Session 0(隔离桌面),
86
86
  * RDP 看不到。找到交互桌面 Session,用计划任务推到那个 Session。
87
+ * 配置环境变量(可选):
88
+ * CAPTCHA_RECOVERY_USER - schtasks /ru 用户名(必需,否则无法跨 Session)
89
+ * CAPTCHA_RECOVERY_PASS - schtasks /rp 密码
87
90
  */
88
91
  let winRecoveryRunning = false;
89
92
 
@@ -98,16 +101,17 @@ async function resolveCaptchaWindows(url, proxyUrl) {
98
101
  const edgeUrl = url.replace("shop.tiktok.com", "www.tiktok.com/shop/pdp");
99
102
  const taskName = "TikTokCaptchaRecovery";
100
103
 
101
- // 1. 找到交互桌面 Session
104
+ // 1. 找到 RDP 交互桌面 Session(Active 且非 Session 0)
102
105
  let sessionId = null;
103
106
  try {
104
107
  const sessions = execSync(
105
- `powershell -NoProfile -Command "query session 2>$null | Select-String 'Active' | ForEach-Object { \\$_.Line }"`,
108
+ `powershell -NoProfile -Command "query session 2>$null | findstr Active"`,
106
109
  { shell: "cmd.exe", timeout: 5000, encoding: "utf-8" },
107
110
  );
108
111
  const lines = sessions.trim().split("\n");
109
112
  for (const line of lines) {
110
- const match = line.match(/>\s*(\d+)\s/);
113
+ // 匹配 RDP 会话: ">rdp-tcp#1 username 2 Active"
114
+ const match = line.match(/\s(\d+)\s+Active/);
111
115
  if (match && match[1] !== "0") {
112
116
  sessionId = parseInt(match[1], 10);
113
117
  break;
@@ -121,15 +125,34 @@ async function resolveCaptchaWindows(url, proxyUrl) {
121
125
  console.error(
122
126
  `[shop-scraper] Windows: Session ${sessionId},用计划任务启动 Edge`,
123
127
  );
128
+ // 清理旧任务
124
129
  try {
125
130
  execSync(`schtasks /delete /tn "${taskName}" /f 2>$null`, {
126
131
  shell: "cmd.exe",
127
132
  });
128
133
  } catch {}
129
- execSync(
130
- `schtasks /create /tn "${taskName}" /tr "msedge ${edgeUrl}" /sc once /st 00:00 /it /f`,
131
- { shell: "cmd.exe", timeout: 10000 },
132
- );
134
+
135
+ const taskUser = process.env.CAPTCHA_RECOVERY_USER || "";
136
+ const taskPass = process.env.CAPTCHA_RECOVERY_PASS || "";
137
+
138
+ if (taskUser && taskPass) {
139
+ // 跨 Session:指定用户 + 交互模式
140
+ const today = new Date().toISOString().slice(0, 10).replace(/-/g, "/");
141
+ execSync(
142
+ `schtasks /create /tn "${taskName}" /tr "msedge \\"${edgeUrl}\\"" /sc once /sd ${today} /st 00:00 /ru "${taskUser}" /rp "${taskPass}" /it /f`,
143
+ { shell: "cmd.exe", timeout: 10000 },
144
+ );
145
+ } else {
146
+ // 回退:无凭证时只能当前 Session(如果 webserver 从 RDP 启动才能看到)
147
+ console.error(
148
+ "[shop-scraper] Windows: 未设置 CAPTCHA_RECOVERY_USER/PASS,计划任务仅限当前 Session",
149
+ );
150
+ execSync(
151
+ `schtasks /create /tn "${taskName}" /tr "msedge \\"${edgeUrl}\\"" /sc once /st 00:00 /it /f`,
152
+ { shell: "cmd.exe", timeout: 10000 },
153
+ );
154
+ }
155
+
133
156
  execSync(`schtasks /run /tn "${taskName}"`, {
134
157
  shell: "cmd.exe",
135
158
  timeout: 10000,