tt-help-cli-ycl 1.3.62 → 1.3.64

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.
@@ -356,7 +356,8 @@ export function startWatchServer(dataAnchor, port = 3000, existingStore) {
356
356
 
357
357
  if (req.method === "GET" && routePath === "/api/redo-job") {
358
358
  const userId = params.userId || "";
359
- const job = store.getNextRedoJob(userId);
359
+ const maxAge = parseInt(params.maxAge) || 43200;
360
+ const job = store.getNextRedoJob(userId, maxAge);
360
361
  if (job) {
361
362
  logJob("REDO-CLAIM", { user: job.uniqueId, clientId: userId });
362
363
  sendJSON(res, 200, { hasJob: true, user: job });
@@ -525,6 +526,66 @@ export function startWatchServer(dataAnchor, port = 3000, existingStore) {
525
526
  return;
526
527
  }
527
528
 
529
+ if (
530
+ req.method === "GET" &&
531
+ routePath === "/api/target-users-by-country"
532
+ ) {
533
+ const result = store.getTargetUsersByCountry(DEFAULT_TARGET_LOCATIONS);
534
+ if (req.headers["accept"]?.includes("text/csv")) {
535
+ const columns = [
536
+ "uniqueId",
537
+ "nickname",
538
+ "followerCount",
539
+ "videoCount",
540
+ "locationCreated",
541
+ "latestVideoTime",
542
+ "refreshTime",
543
+ "status",
544
+ "sources",
545
+ ];
546
+ const allUsers = [];
547
+ for (const country of result.countries) {
548
+ for (const u of country.users) {
549
+ allUsers.push({
550
+ uniqueId: u.uniqueId,
551
+ nickname: u.nickname || "",
552
+ followerCount: u.followerCount ?? 0,
553
+ videoCount: u.videoCount ?? 0,
554
+ locationCreated: u.locationCreated || "",
555
+ latestVideoTime: u.latestVideoTime
556
+ ? new Date(u.latestVideoTime * 1000)
557
+ .toISOString()
558
+ .slice(0, 19)
559
+ .replace("T", " ")
560
+ : "",
561
+ refreshTime: u.refreshTime
562
+ ? new Date(u.refreshTime)
563
+ .toISOString()
564
+ .slice(0, 19)
565
+ .replace("T", " ")
566
+ : "",
567
+ status: u.status || "",
568
+ sources: (u.sources || []).join(";"),
569
+ });
570
+ }
571
+ }
572
+ res.writeHead(200, {
573
+ "Content-Type": "text/csv; charset=utf-8",
574
+ "Content-Disposition":
575
+ 'attachment; filename="target-users-by-country.csv"',
576
+ });
577
+ const BOM = "\uFEFF";
578
+ const header = columns.join(",");
579
+ const lines = allUsers.map((r) =>
580
+ columns.map((c) => csvEscape(r[c])).join(","),
581
+ );
582
+ res.end(BOM + [header, ...lines].join("\r\n"));
583
+ } else {
584
+ sendJSON(res, 200, result);
585
+ }
586
+ return;
587
+ }
588
+
528
589
  if (req.method === "GET" && routePath === "/api/client-errors") {
529
590
  sendJSON(res, 200, { clients: store.getClientErrors() });
530
591
  return;
@@ -563,6 +624,8 @@ export function startWatchServer(dataAnchor, port = 3000, existingStore) {
563
624
  location: params.location,
564
625
  limit: params.limit,
565
626
  offset: params.offset,
627
+ hasVideo: params.hasVideo,
628
+ hasFollower: params.hasFollower,
566
629
  });
567
630
  sendJSON(res, 200, result);
568
631
  return;
@@ -589,10 +652,17 @@ export function startWatchServer(dataAnchor, port = 3000, existingStore) {
589
652
  let result;
590
653
  if (body.uniqueId) {
591
654
  result = store.restoreRawJobById(body.uniqueId);
592
- } else if (body.search || body.location) {
655
+ } else if (
656
+ body.search ||
657
+ body.location ||
658
+ body.hasVideo ||
659
+ body.hasFollower
660
+ ) {
593
661
  result = store.restoreRawJobsByFilter({
594
662
  search: body.search || "",
595
663
  location: body.location || "",
664
+ hasVideo: body.hasVideo,
665
+ hasFollower: body.hasFollower,
596
666
  });
597
667
  } else if (body.country) {
598
668
  result = store.restoreRawJobsByCountry(body.country);
@@ -628,6 +698,24 @@ export function startWatchServer(dataAnchor, port = 3000, existingStore) {
628
698
  return;
629
699
  }
630
700
 
701
+ if (
702
+ req.method === "POST" &&
703
+ routePath === "/api/pending-by-country/reset"
704
+ ) {
705
+ try {
706
+ const body = await readBody(req);
707
+ const result = store.resetPendingByCountry(body.country);
708
+ if (result.error) {
709
+ sendJSON(res, 400, result);
710
+ return;
711
+ }
712
+ sendJSON(res, 200, result);
713
+ } catch (e) {
714
+ sendJSON(res, 400, { error: e.message });
715
+ }
716
+ return;
717
+ }
718
+
631
719
  if (
632
720
  req.method === "DELETE" &&
633
721
  routePath.startsWith("/api/client-error/")
@@ -683,6 +771,7 @@ export function startWatchServer(dataAnchor, port = 3000, existingStore) {
683
771
  followerCount: u.followerCount,
684
772
  locationCreated: u.locationCreated,
685
773
  latestVideoTime: u.latestVideoTime,
774
+ refreshTime: u.refreshTime,
686
775
  guessedLocation: u.guessedLocation,
687
776
  pinned: u.pinned,
688
777
  processedAt: u.processedAt,
@@ -1,213 +0,0 @@
1
- import {
2
- delay,
3
- retryWithBackoff,
4
- detectPageError,
5
- assertPageUrl,
6
- } from "./modules/page-helpers.js";
7
- import { detectCaptcha } from "./modules/captcha-handler.js";
8
- import { getUserInfo, collectVideos } from "../videos/core.js";
9
- import { extractFollowAndFollowers } from "./modules/follow-extractor.js";
10
- import { processExplore } from "./explore-core.js";
11
- import { DEFAULT_TARGET_LOCATIONS_CSV } from "../lib/target-locations.js";
12
-
13
- export async function processRefresh(page, username, serverUrl, options, log) {
14
- const { maxFollowing = 100, maxFollowers = 100, maxVideos = 100 } = options;
15
-
16
- const result = {
17
- userInfo: null,
18
- discoveredVideoAuthors: [],
19
- discoveredFollowing: [],
20
- discoveredFollowers: [],
21
- newUsersAdded: 0,
22
- collectedVideos: 0,
23
- error: null,
24
- };
25
-
26
- try {
27
- log(` 访问 @${username} 主页...`);
28
- const homeUrl = `https://www.tiktok.com/@${username}`;
29
- await retryWithBackoff(
30
- async () => {
31
- await page.goto(homeUrl, {
32
- waitUntil: "domcontentloaded",
33
- timeout: 30000,
34
- });
35
- assertPageUrl(page, `@${username}`);
36
- },
37
- { log },
38
- );
39
- await page
40
- .waitForSelector('[class*="DivVideoList"]', { timeout: 10000 })
41
- .catch(() => {});
42
- await delay(1000, 2000);
43
-
44
- log(" 获取用户信息...");
45
- const info = await getUserInfo(page);
46
- if (info) {
47
- result.userInfo = info;
48
- log(
49
- ` 用户: ${info.nickname || username} | 粉丝: ${info.followerCount || "-"} | 视频: ${info.videoCount || "-"}`,
50
- );
51
- }
52
-
53
- const captcha = await detectCaptcha(page);
54
- if (captcha && captcha.visible) {
55
- log(`[验证码] @${username} 页面出现验证码`);
56
- result.captchaDetected = true;
57
- result.captchaStage = result.captchaStage || "video-page";
58
- result.captchaMessage = result.captchaMessage || "视频页出现验证码";
59
- }
60
-
61
- // 采集视频
62
- log(` 采集视频 (最多 ${maxVideos} 个)...`);
63
- const videoList = await collectVideos(page, username, maxVideos, log);
64
- const videoArray = videoList ? [...videoList.values()] : [];
65
- result.collectedVideos = videoArray.length;
66
- result.discoveredVideoAuthors = videoArray.map((v) => v.author);
67
-
68
- if (videoArray.length <= 0) {
69
- result.noVideo = true;
70
- const pageError = await detectPageError(page);
71
- if (pageError) {
72
- result.restricted = true;
73
- log(` @${username} 页面受限(${pageError}),标记跳过`);
74
- }
75
- return result;
76
- }
77
-
78
- // 采集关注和粉丝
79
- log(` 采集关注 (最多 ${maxFollowing}) + 粉丝 (最多 ${maxFollowers})...`);
80
- try {
81
- const followResult = await extractFollowAndFollowers(page, {
82
- maxFollowing,
83
- maxFollowers,
84
- });
85
- result.discoveredFollowing = followResult.following || [];
86
- result.discoveredFollowers = followResult.followers || [];
87
- log(
88
- ` 关注: ${result.discoveredFollowing.length}, 粉丝: ${result.discoveredFollowers.length}`,
89
- );
90
- } catch (e) {
91
- log(` [关注/粉丝采集失败] ${e.message}`);
92
- result.discoveredFollowing = [];
93
- result.discoveredFollowers = [];
94
- }
95
-
96
- // 处理新发现的用户(关注 + 粉丝),循环执行完整 explore
97
- // follow-extractor 返回 [handle, displayName] 数组
98
- const allDiscovered = [
99
- ...result.discoveredFollowing.map((h) => ({
100
- handle: Array.isArray(h) ? h[0] : h,
101
- source: "refresh-following",
102
- })),
103
- ...result.discoveredFollowers.map((h) => ({
104
- handle: Array.isArray(h) ? h[0] : h,
105
- source: "refresh-follower",
106
- })),
107
- ];
108
-
109
- for (const { handle, source } of allDiscovered) {
110
- const uniqueId = handle.replace("@", "");
111
-
112
- // 检查用户是否已存在
113
- const existsResp = await fetch(
114
- `${serverUrl}/api/user-exists/${encodeURIComponent(uniqueId)}`,
115
- );
116
- const existsData = await existsResp.json();
117
-
118
- if (existsData.exists) {
119
- continue;
120
- }
121
-
122
- log(` [新用户] @${uniqueId} 不存在,开始探索 (来源: ${source})...`);
123
- await delay(1000, 2000);
124
-
125
- // 对新用户做完整 explore(与 explore 命令逻辑一致)
126
- const exploreResult = await processExplore(
127
- page,
128
- uniqueId,
129
- {
130
- maxComments: 10,
131
- maxGuess: 0,
132
- enableFollow: true,
133
- maxFollowing: 5,
134
- maxFollowers: 5,
135
- location: DEFAULT_TARGET_LOCATIONS_CSV,
136
- },
137
- log,
138
- );
139
-
140
- // 提交 explore 结果到服务端(和 explore 命令的 commitJob 一致)
141
- if (exploreResult.userInfo) {
142
- const guessedLocation = exploreResult.locationCreated || null;
143
-
144
- const payload = {
145
- userInfo: exploreResult.userInfo || {},
146
- discoveredVideoAuthors: (
147
- exploreResult.discoveredVideoAuthors || []
148
- ).map((item) =>
149
- typeof item === "object" ? { ...item, guessedLocation } : item,
150
- ),
151
- discoveredCommentAuthors: (
152
- exploreResult.discoveredCommentAuthors || []
153
- ).map((author) => ({ author, guessedLocation })),
154
- discoveredGuessAuthors: (
155
- exploreResult.discoveredGuessAuthors || []
156
- ).map((author) => ({ author, guessedLocation })),
157
- discoveredFollowing: (exploreResult.discoveredFollowing || []).map(
158
- (f) => ({
159
- handle: Array.isArray(f) ? f[0] : f,
160
- displayName: Array.isArray(f) ? f[1] : null,
161
- guessedLocation,
162
- }),
163
- ),
164
- discoveredFollowers: (exploreResult.discoveredFollowers || []).map(
165
- (f) => ({
166
- handle: Array.isArray(f) ? f[0] : f,
167
- displayName: Array.isArray(f) ? f[1] : null,
168
- guessedLocation,
169
- }),
170
- ),
171
- processed: exploreResult.processed,
172
- hasFollowData: exploreResult.hasFollowData,
173
- keepFollow: exploreResult.keepFollow,
174
- locationCreated: exploreResult.locationCreated,
175
- noVideo: exploreResult.noVideo,
176
- restricted: exploreResult.restricted,
177
- error: exploreResult.error,
178
- };
179
-
180
- const addResp = await fetch(
181
- `${serverUrl}/api/explore-new/${uniqueId}`,
182
- {
183
- method: "POST",
184
- headers: { "Content-Type": "application/json" },
185
- body: JSON.stringify(payload),
186
- },
187
- );
188
- const addResult = await addResp.json();
189
-
190
- if (!addResult.saved) {
191
- log(` [跳过] @${uniqueId} 提交失败`);
192
- continue;
193
- }
194
-
195
- result.newUsersAdded++;
196
- if (exploreResult.captchaDetected) {
197
- result.captchaDetected = true;
198
- }
199
- log(
200
- ` [已提交] @${uniqueId} ${addResult.created ? "(新用户)" : "(已存在)"} | 发现: ${addResult.newUsers?.length || 0} 个`,
201
- );
202
- }
203
-
204
- await delay(2000, 4000);
205
- }
206
- } catch (e) {
207
- log(` [错误] ${e.message}`);
208
- result.error = e.message;
209
- result.errorStack = e.stack || "";
210
- }
211
-
212
- return result;
213
- }