tt-help-cli-ycl 1.4.47 → 1.4.48
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/lib/shop-scraper.mjs +22 -57
package/package.json
CHANGED
package/src/lib/shop-scraper.mjs
CHANGED
|
@@ -83,10 +83,7 @@ function extractJsonByKey(html, keyPattern) {
|
|
|
83
83
|
|
|
84
84
|
/**
|
|
85
85
|
* Windows: 后台服务的 Playwright 浏览器在 Session 0(隔离桌面),
|
|
86
|
-
* RDP
|
|
87
|
-
* 配置环境变量(可选):
|
|
88
|
-
* CAPTCHA_RECOVERY_USER - schtasks /ru 用户名(必需,否则无法跨 Session)
|
|
89
|
-
* CAPTCHA_RECOVERY_PASS - schtasks /rp 密码
|
|
86
|
+
* RDP 看不到。用计划任务推到交互桌面(/it 自动定位已登录用户,无需密码)。
|
|
90
87
|
*/
|
|
91
88
|
let winRecoveryRunning = false;
|
|
92
89
|
|
|
@@ -101,30 +98,9 @@ async function resolveCaptchaWindows(url, proxyUrl) {
|
|
|
101
98
|
const edgeUrl = url.replace("shop.tiktok.com", "www.tiktok.com/shop/pdp");
|
|
102
99
|
const taskName = "TikTokCaptchaRecovery";
|
|
103
100
|
|
|
104
|
-
// 1.
|
|
105
|
-
let
|
|
101
|
+
// 1. 用计划任务推到交互桌面(/it 自动定位已登录用户)
|
|
102
|
+
let taskCreated = false;
|
|
106
103
|
try {
|
|
107
|
-
const sessions = execSync(
|
|
108
|
-
`powershell -NoProfile -Command "query session 2>$null | findstr Active"`,
|
|
109
|
-
{ shell: "cmd.exe", timeout: 5000, encoding: "utf-8" },
|
|
110
|
-
);
|
|
111
|
-
const lines = sessions.trim().split("\n");
|
|
112
|
-
for (const line of lines) {
|
|
113
|
-
// 匹配 RDP 会话: ">rdp-tcp#1 username 2 Active"
|
|
114
|
-
const match = line.match(/\s(\d+)\s+Active/);
|
|
115
|
-
if (match && match[1] !== "0") {
|
|
116
|
-
sessionId = parseInt(match[1], 10);
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
} catch {
|
|
121
|
-
console.error("[shop-scraper] Windows: 无法获取交互 Session");
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (sessionId) {
|
|
125
|
-
console.error(
|
|
126
|
-
`[shop-scraper] Windows: Session ${sessionId},用计划任务启动 Edge`,
|
|
127
|
-
);
|
|
128
104
|
// 清理旧任务
|
|
129
105
|
try {
|
|
130
106
|
execSync(`schtasks /delete /tn "${taskName}" /f 2>$null`, {
|
|
@@ -132,31 +108,30 @@ async function resolveCaptchaWindows(url, proxyUrl) {
|
|
|
132
108
|
});
|
|
133
109
|
} catch {}
|
|
134
110
|
|
|
135
|
-
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
-
}
|
|
111
|
+
// 获取当天日期,格式 yyyy/MM/dd
|
|
112
|
+
const today = execSync(
|
|
113
|
+
`powershell -NoProfile -Command "Get-Date -Format yyyy/MM/dd"`,
|
|
114
|
+
{ shell: "cmd.exe", timeout: 3000, encoding: "utf-8" },
|
|
115
|
+
).trim();
|
|
155
116
|
|
|
117
|
+
execSync(
|
|
118
|
+
`schtasks /create /tn "${taskName}" /tr "msedge \\"${edgeUrl}\\"" /sc once /sd ${today} /st 23:59 /it /f`,
|
|
119
|
+
{ shell: "cmd.exe", timeout: 10000 },
|
|
120
|
+
);
|
|
156
121
|
execSync(`schtasks /run /tn "${taskName}"`, {
|
|
157
122
|
shell: "cmd.exe",
|
|
158
123
|
timeout: 10000,
|
|
159
124
|
});
|
|
125
|
+
taskCreated = true;
|
|
126
|
+
console.error(
|
|
127
|
+
"[shop-scraper] Windows: 计划任务已启动 Edge,请在 RDP 中完成验证码",
|
|
128
|
+
);
|
|
129
|
+
} catch (e) {
|
|
130
|
+
console.error("[shop-scraper] Windows: 计划任务失败:", e.message);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// 延迟删除任务
|
|
134
|
+
if (taskCreated) {
|
|
160
135
|
setTimeout(() => {
|
|
161
136
|
try {
|
|
162
137
|
execSync(`schtasks /delete /tn "${taskName}" /f 2>$null`, {
|
|
@@ -164,16 +139,6 @@ async function resolveCaptchaWindows(url, proxyUrl) {
|
|
|
164
139
|
});
|
|
165
140
|
} catch {}
|
|
166
141
|
}, 10000);
|
|
167
|
-
} else {
|
|
168
|
-
console.error(
|
|
169
|
-
"[shop-scraper] Windows: 未找到交互 Session,尝试直接 start",
|
|
170
|
-
);
|
|
171
|
-
try {
|
|
172
|
-
execSync(`start "" "microsoft-edge:${edgeUrl}"`, {
|
|
173
|
-
shell: "cmd.exe",
|
|
174
|
-
timeout: 5000,
|
|
175
|
-
});
|
|
176
|
-
} catch {}
|
|
177
142
|
}
|
|
178
143
|
|
|
179
144
|
// 2. 轮询 undici 等待 IP 信用恢复
|