tt-help-cli-ycl 1.4.54 → 1.4.55

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.54",
3
+ "version": "1.4.55",
4
4
  "description": "TikTok user & video data scraper - extract ttSeller, verified, locationCreated from HTML source",
5
5
  "type": "module",
6
6
  "bin": {
package/src/lib/args.js CHANGED
@@ -407,7 +407,8 @@ function parseWebserverArgs(args) {
407
407
  let webserverPort = 3000;
408
408
  let webserverPoolSize = 0;
409
409
  let webserverProxy = null;
410
- let webserverNotify = null;
410
+ // 默认汇报到 ~/.tt-help.json 中配置的 server 地址
411
+ let webserverNotify = defaultServer;
411
412
 
412
413
  for (let i = 0; i < args.length; i++) {
413
414
  const arg = args[i];
@@ -419,9 +420,9 @@ function parseWebserverArgs(args) {
419
420
  webserverProxy = args[++i] || null;
420
421
  } else if (arg === "--notify") {
421
422
  const next = args[i + 1];
422
- // 没写地址或下一个是别的参数 → 使用默认 watch 服务器
423
+ // 没写地址或下一个是别的参数 → 使用配置中的 server 地址
423
424
  if (!next || next.startsWith("--")) {
424
- webserverNotify = "http://117.71.53.99:17301";
425
+ webserverNotify = defaultServer;
425
426
  } else {
426
427
  webserverNotify = args[++i];
427
428
  }
@@ -238,15 +238,17 @@ async function handleTiktokProduct(req, res) {
238
238
  // 防止重复弹浏览器
239
239
  let captchaRecoveryRunning = false;
240
240
 
241
- async function scheduleCaptchaRecovery(url, proxy) {
242
- if (captchaRecoveryRunning) {
243
- console.error("[webserver] Captcha recovery already in progress, skipping");
241
+ // 通知 Watch Server:带重试,不受 captchaRecoveryRunning 锁限制
242
+ // captchaNotifyUrl 默认来自 ~/.tt-help.json 的 server 配置
243
+ async function notifyCaptchaToWatch(url, maxRetries = 3) {
244
+ if (!SCRAPER_CONFIG.captchaNotifyUrl) {
245
+ console.error(
246
+ "[webserver] Captcha detected but notify URL is empty, check --notify or ~/.tt-help.json server config",
247
+ );
244
248
  return;
245
249
  }
246
- captchaRecoveryRunning = true;
247
250
 
248
- // 通知 Watch Server:这台机器出现验证码需要人工处理
249
- if (SCRAPER_CONFIG.captchaNotifyUrl) {
251
+ for (let attempt = 1; attempt <= maxRetries; attempt++) {
250
252
  try {
251
253
  await fetch(`${SCRAPER_CONFIG.captchaNotifyUrl}/api/error-report`, {
252
254
  method: "POST",
@@ -261,10 +263,35 @@ async function scheduleCaptchaRecovery(url, proxy) {
261
263
  }),
262
264
  });
263
265
  console.error("[webserver] Captcha alert sent to watch server");
266
+ return;
264
267
  } catch (e) {
265
- console.error("[webserver] Failed to notify watch server:", e.message);
268
+ if (attempt < maxRetries) {
269
+ const delay = attempt * 2000;
270
+ console.error(
271
+ `[webserver] Failed to notify watch server (attempt ${attempt}/${maxRetries}): ${e.message}, retrying in ${delay}ms...`,
272
+ );
273
+ await new Promise((r) => setTimeout(r, delay));
274
+ } else {
275
+ console.error(
276
+ `[webserver] Failed to notify watch server after ${maxRetries} attempts: ${e.message}`,
277
+ );
278
+ }
266
279
  }
267
280
  }
281
+ }
282
+
283
+ async function scheduleCaptchaRecovery(url, proxy) {
284
+ // 通知 Watch Server — 独立于浏览器恢复,每次验证码都尝试上报(带重试)
285
+ await notifyCaptchaToWatch(url);
286
+
287
+ // 防止重复弹浏览器
288
+ if (captchaRecoveryRunning) {
289
+ console.error(
290
+ "[webserver] Captcha recovery already in progress, skipping browser",
291
+ );
292
+ return;
293
+ }
294
+ captchaRecoveryRunning = true;
268
295
 
269
296
  try {
270
297
  const { getProductInfo } = await import("../lib/shop-scraper.mjs");