tt-help-cli-ycl 1.3.52 → 1.3.57
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/attach.js +25 -13
- package/src/cli/info.js +50 -28
- package/src/cli/open.js +3 -2
- package/src/lib/parse-ssr.mjs +70 -15
- package/src/lib/scrape.js +2 -3
- package/src/lib/tiktok-scraper.mjs +118 -217
- package/src/scraper/explore-core.js +2 -0
- package/src/watch/data-store.js +488 -112
- package/src/watch/public/index.html +115 -16
- package/src/watch/server.js +45 -3
- package/scripts/run-explore copy.bat +0 -101
- package/scripts/test-captcha-lib.mjs +0 -68
- package/scripts/test-captcha.mjs +0 -81
- package/scripts/test-incognito-lib.mjs +0 -36
- package/scripts/test-login-state.mjs +0 -128
- package/scripts/test-safe-click.mjs +0 -45
- package/scripts/test-watch-db-smoke.mjs +0 -246
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { ensureBrowserReady } from '../src/lib/browser/cdp.js';
|
|
2
|
-
|
|
3
|
-
async function main() {
|
|
4
|
-
const browser = await ensureBrowserReady();
|
|
5
|
-
const defaultContext = browser.contexts()[0];
|
|
6
|
-
const page = defaultContext.pages()[0] || await defaultContext.newPage();
|
|
7
|
-
|
|
8
|
-
// 确保在 tiktok 页面
|
|
9
|
-
if (!page.url().includes('tiktok.com')) {
|
|
10
|
-
console.error('当前不在 TikTok 页面:', page.url());
|
|
11
|
-
await page.goto('https://www.tiktok.com', { waitUntil: 'domcontentloaded', timeout: 30000 });
|
|
12
|
-
await new Promise(r => setTimeout(r, 3000));
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
console.error('当前 URL:', page.url());
|
|
16
|
-
|
|
17
|
-
// 1. 检测现有 isLoggedIn 的逻辑
|
|
18
|
-
const currentUserMenu = await page.evaluate(() => {
|
|
19
|
-
const selectors = [
|
|
20
|
-
'[class*="UserMenu"]',
|
|
21
|
-
'[class*="user-menu"]',
|
|
22
|
-
'[class*="CurrentUserInfo"]',
|
|
23
|
-
];
|
|
24
|
-
const results = {};
|
|
25
|
-
for (const sel of selectors) {
|
|
26
|
-
const el = document.querySelector(sel);
|
|
27
|
-
results[sel] = !!el;
|
|
28
|
-
if (el) {
|
|
29
|
-
results[sel + '_class'] = el.className;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return results;
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
console.error('\n=== 当前选择器检测结果 ===');
|
|
36
|
-
console.error(JSON.stringify(currentUserMenu, null, 2));
|
|
37
|
-
|
|
38
|
-
const hasLoginButton = await page.evaluate(() => {
|
|
39
|
-
const buttons = Array.from(document.querySelectorAll('button, [role="button"]'));
|
|
40
|
-
const loginButtons = buttons.filter(el =>
|
|
41
|
-
/^(登录|Log in|Sign in)$/i.test(el.textContent.trim())
|
|
42
|
-
);
|
|
43
|
-
return {
|
|
44
|
-
total: buttons.length,
|
|
45
|
-
loginCount: loginButtons.length,
|
|
46
|
-
samples: loginButtons.slice(0, 5).map(el => ({
|
|
47
|
-
text: el.textContent.trim(),
|
|
48
|
-
class: el.className,
|
|
49
|
-
})),
|
|
50
|
-
};
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
console.error('\n=== 登录按钮检测 ===');
|
|
54
|
-
console.error(JSON.stringify(hasLoginButton, null, 2));
|
|
55
|
-
|
|
56
|
-
// 2. 用更宽泛的方式找用户相关元素
|
|
57
|
-
const broadSearch = await page.evaluate(() => {
|
|
58
|
-
const allClasses = [];
|
|
59
|
-
|
|
60
|
-
// 搜索可能的用户头像/菜单元素
|
|
61
|
-
const candidates = [];
|
|
62
|
-
|
|
63
|
-
// 顶部导航区域
|
|
64
|
-
const navArea = document.querySelector('[class*="nav"], [class*="Header"], [class*="header"]');
|
|
65
|
-
if (navArea) {
|
|
66
|
-
const avatars = navArea.querySelectorAll('[class*="avatar"], [class*="Avatar"], [class*="photo"], [class*="Photo"], [class*="image"], [class*="Image"]');
|
|
67
|
-
avatars.forEach(el => {
|
|
68
|
-
candidates.push({
|
|
69
|
-
tag: el.tagName,
|
|
70
|
-
class: el.className.substring(0, 200),
|
|
71
|
-
text: el.textContent?.substring(0, 50),
|
|
72
|
-
parent: el.parentElement?.className?.substring(0, 100),
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// 搜索包含用户信息的链接
|
|
78
|
-
const profileLinks = Array.from(document.querySelectorAll('a[href*="/@"]'));
|
|
79
|
-
const profileSamples = profileLinks.slice(0, 10).map(el => ({
|
|
80
|
-
href: el.href,
|
|
81
|
-
class: el.className?.substring(0, 100),
|
|
82
|
-
text: el.textContent?.substring(0, 50),
|
|
83
|
-
}));
|
|
84
|
-
|
|
85
|
-
// 搜索所有包含 User 关键字的类名
|
|
86
|
-
const userElements = Array.from(document.querySelectorAll('*')).filter(el =>
|
|
87
|
-
el.className && typeof el.className === 'string' &&
|
|
88
|
-
/User|user|Profile|profile/.test(el.className) &&
|
|
89
|
-
el.tagName !== 'STYLE' && el.tagName !== 'SCRIPT'
|
|
90
|
-
).slice(0, 30).map(el => ({
|
|
91
|
-
tag: el.tagName,
|
|
92
|
-
class: el.className.substring(0, 150),
|
|
93
|
-
text: el.textContent?.substring(0, 30),
|
|
94
|
-
}));
|
|
95
|
-
|
|
96
|
-
return {
|
|
97
|
-
navAreaFound: !!navArea,
|
|
98
|
-
avatarCandidates: candidates,
|
|
99
|
-
profileLinks: profileSamples,
|
|
100
|
-
userElements,
|
|
101
|
-
};
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
console.error('\n=== 宽泛搜索 ===');
|
|
105
|
-
console.error(JSON.stringify(broadSearch, null, 2));
|
|
106
|
-
|
|
107
|
-
// 3. 截图
|
|
108
|
-
await page.screenshot({ path: '/tmp/login-debug.png' });
|
|
109
|
-
console.error('\n截图已保存到 /tmp/login-debug.png');
|
|
110
|
-
|
|
111
|
-
// 4. 汇总判断
|
|
112
|
-
const isLoggedIn = currentUserMenu['[class*="UserMenu"]'] ||
|
|
113
|
-
currentUserMenu['[class*="user-menu"]'] ||
|
|
114
|
-
currentUserMenu['[class*="CurrentUserInfo"]'] ||
|
|
115
|
-
broadSearch.userElements.length > 0;
|
|
116
|
-
|
|
117
|
-
console.error('\n=== 结论 ===');
|
|
118
|
-
console.error('isLoggedIn 函数返回:', !!(currentUserMenu['[class*="UserMenu"]'] || currentUserMenu['[class*="user-menu"]'] || currentUserMenu['[class*="CurrentUserInfo"]']) && !hasLoginButton.loginCount);
|
|
119
|
-
console.error('宽泛搜索是否找到用户元素:', broadSearch.userElements.length > 0);
|
|
120
|
-
console.error('找到用户相关元素数量:', broadSearch.userElements.length);
|
|
121
|
-
console.error('头像候选数量:', broadSearch.avatarCandidates.length);
|
|
122
|
-
console.error('Profile 链接数量:', broadSearch.profileLinks.length);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
main().catch(err => {
|
|
126
|
-
console.error('错误:', err);
|
|
127
|
-
process.exit(1);
|
|
128
|
-
});
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { chromium } from 'playwright';
|
|
2
|
-
import { safeClickComment, detectCaptcha } from '../src/scraper/modules/captcha-handler.mjs';
|
|
3
|
-
import { ensureBrowserReady } from '../src/lib/browser/cdp.js';
|
|
4
|
-
|
|
5
|
-
const URL = 'https://www.tiktok.com/@mariaelenasanchez607/video/7630110959650000150';
|
|
6
|
-
|
|
7
|
-
async function main() {
|
|
8
|
-
const browser = await ensureBrowserReady();
|
|
9
|
-
const defaultContext = browser.contexts()[0];
|
|
10
|
-
const page = defaultContext.pages()[0] || await defaultContext.newPage();
|
|
11
|
-
|
|
12
|
-
for (let i = 1; i <= 3; i++) {
|
|
13
|
-
console.error(`\n===== 第 ${i} 轮 =====`);
|
|
14
|
-
await page.goto(URL, { waitUntil: 'domcontentloaded', timeout: 30000 });
|
|
15
|
-
await new Promise(r => setTimeout(r, 5000));
|
|
16
|
-
|
|
17
|
-
const result = await safeClickComment(page);
|
|
18
|
-
console.error('结果:', JSON.stringify(result));
|
|
19
|
-
|
|
20
|
-
const stillThere = await detectCaptcha(page);
|
|
21
|
-
console.error('验证码残留:', !!stillThere);
|
|
22
|
-
|
|
23
|
-
await page.screenshot({ path: `/tmp/safe-click-run-${i}.png` });
|
|
24
|
-
|
|
25
|
-
// 关闭评论面板
|
|
26
|
-
await page.evaluate(() => {
|
|
27
|
-
const rightPanel = document.querySelector('[class*="RightPanelContainer"]');
|
|
28
|
-
if (rightPanel) {
|
|
29
|
-
const tabContainer = rightPanel.querySelector('[class*="TabContainer"]');
|
|
30
|
-
if (tabContainer) {
|
|
31
|
-
const closeOverlay = tabContainer.querySelector('div:last-child');
|
|
32
|
-
if (closeOverlay) closeOverlay.click();
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
await new Promise(r => setTimeout(r, 2000));
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
console.error('\n完成');
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
main().catch(err => {
|
|
43
|
-
console.error('错误:', err);
|
|
44
|
-
process.exit(1);
|
|
45
|
-
});
|
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import { mkdtempSync, rmSync } from "node:fs";
|
|
3
|
-
import os from "node:os";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
|
|
6
|
-
import { createStore, closeStoreDb } from "../src/watch/data-store.js";
|
|
7
|
-
import { startWatchServer } from "../src/watch/server.js";
|
|
8
|
-
|
|
9
|
-
function createTempDbPath(prefix) {
|
|
10
|
-
const dir = mkdtempSync(path.join(os.tmpdir(), `${prefix}-`));
|
|
11
|
-
return {
|
|
12
|
-
dir,
|
|
13
|
-
dbPath: path.join(dir, "result.db"),
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function cleanupTempDir(dir) {
|
|
18
|
-
rmSync(dir, { recursive: true, force: true });
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function seedClaimStore(store) {
|
|
22
|
-
store.addUser({
|
|
23
|
-
uniqueId: "follow-tier2",
|
|
24
|
-
status: "pending",
|
|
25
|
-
followerCount: 100,
|
|
26
|
-
videoCount: 1,
|
|
27
|
-
guessedLocation: "DE",
|
|
28
|
-
sources: ["following"],
|
|
29
|
-
});
|
|
30
|
-
store.addUser({
|
|
31
|
-
uniqueId: "seller-tier2",
|
|
32
|
-
status: "pending",
|
|
33
|
-
followerCount: 50,
|
|
34
|
-
videoCount: 1,
|
|
35
|
-
guessedLocation: "DE",
|
|
36
|
-
ttSeller: true,
|
|
37
|
-
verified: false,
|
|
38
|
-
sources: ["comment"],
|
|
39
|
-
});
|
|
40
|
-
store.addUser({
|
|
41
|
-
uniqueId: "seed-tier1",
|
|
42
|
-
status: "pending",
|
|
43
|
-
followerCount: 10,
|
|
44
|
-
videoCount: 1,
|
|
45
|
-
guessedLocation: "PL",
|
|
46
|
-
sources: ["seed"],
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function seedWatchStore(store) {
|
|
51
|
-
store.addUser({
|
|
52
|
-
uniqueId: "seed-tier1",
|
|
53
|
-
nickname: "Seed User",
|
|
54
|
-
status: "pending",
|
|
55
|
-
followerCount: 10,
|
|
56
|
-
videoCount: 1,
|
|
57
|
-
guessedLocation: "PL",
|
|
58
|
-
ttSeller: false,
|
|
59
|
-
verified: false,
|
|
60
|
-
sources: ["seed"],
|
|
61
|
-
});
|
|
62
|
-
store.addUser({
|
|
63
|
-
uniqueId: "seller-target",
|
|
64
|
-
nickname: "Seller Target",
|
|
65
|
-
status: "pending",
|
|
66
|
-
followerCount: 500,
|
|
67
|
-
videoCount: 1,
|
|
68
|
-
guessedLocation: "DE",
|
|
69
|
-
locationCreated: "DE",
|
|
70
|
-
ttSeller: true,
|
|
71
|
-
verified: false,
|
|
72
|
-
sources: ["comment"],
|
|
73
|
-
});
|
|
74
|
-
store.addUser({
|
|
75
|
-
uniqueId: "follow-tier2",
|
|
76
|
-
nickname: "Follow User",
|
|
77
|
-
status: "pending",
|
|
78
|
-
followerCount: 300,
|
|
79
|
-
videoCount: 1,
|
|
80
|
-
guessedLocation: "FR",
|
|
81
|
-
ttSeller: false,
|
|
82
|
-
verified: false,
|
|
83
|
-
sources: ["following"],
|
|
84
|
-
});
|
|
85
|
-
store.addUser({
|
|
86
|
-
uniqueId: "pending-update",
|
|
87
|
-
nickname: "Needs Update",
|
|
88
|
-
status: "pending",
|
|
89
|
-
guessedLocation: "US",
|
|
90
|
-
ttSeller: null,
|
|
91
|
-
verified: false,
|
|
92
|
-
userUpdateCount: 0,
|
|
93
|
-
sources: ["comment"],
|
|
94
|
-
});
|
|
95
|
-
store.addUser({
|
|
96
|
-
uniqueId: "done-es",
|
|
97
|
-
nickname: "Done ES",
|
|
98
|
-
status: "done",
|
|
99
|
-
followerCount: 800,
|
|
100
|
-
videoCount: 3,
|
|
101
|
-
guessedLocation: "ES",
|
|
102
|
-
locationCreated: "ES",
|
|
103
|
-
ttSeller: true,
|
|
104
|
-
verified: false,
|
|
105
|
-
processedAt: Date.now(),
|
|
106
|
-
processed: true,
|
|
107
|
-
sources: ["processed"],
|
|
108
|
-
});
|
|
109
|
-
store.addUser({
|
|
110
|
-
uniqueId: "restricted-it",
|
|
111
|
-
nickname: "Restricted IT",
|
|
112
|
-
status: "restricted",
|
|
113
|
-
locationCreated: "IT",
|
|
114
|
-
ttSeller: false,
|
|
115
|
-
verified: false,
|
|
116
|
-
sources: ["comment"],
|
|
117
|
-
});
|
|
118
|
-
store.addUser({
|
|
119
|
-
uniqueId: "error-user",
|
|
120
|
-
nickname: "Error User",
|
|
121
|
-
status: "error",
|
|
122
|
-
locationCreated: "US",
|
|
123
|
-
ttSeller: false,
|
|
124
|
-
verified: false,
|
|
125
|
-
sources: ["comment"],
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
async function testClaimPriorityAndRenewal() {
|
|
130
|
-
const { dir, dbPath } = createTempDbPath("tt-watch-claim");
|
|
131
|
-
try {
|
|
132
|
-
const store = createStore(dbPath);
|
|
133
|
-
seedClaimStore(store);
|
|
134
|
-
|
|
135
|
-
const first = store.claimNextJob("worker-a", 5 * 60 * 1000, null, true);
|
|
136
|
-
assert.ok(first, "expected a claim for logged-in worker");
|
|
137
|
-
assert.equal(first.uniqueId, "seed-tier1");
|
|
138
|
-
|
|
139
|
-
const renewed = store.claimNextJob("worker-a", 5 * 60 * 1000, null, true);
|
|
140
|
-
assert.ok(renewed, "expected renewal claim for same worker");
|
|
141
|
-
assert.equal(renewed.uniqueId, "seed-tier1");
|
|
142
|
-
assert.ok(
|
|
143
|
-
renewed.claimedAt >= first.claimedAt,
|
|
144
|
-
"expected renewal claimedAt to advance or stay equal",
|
|
145
|
-
);
|
|
146
|
-
|
|
147
|
-
const loggedOut = store.claimNextJob(
|
|
148
|
-
"worker-b",
|
|
149
|
-
5 * 60 * 1000,
|
|
150
|
-
null,
|
|
151
|
-
false,
|
|
152
|
-
);
|
|
153
|
-
assert.ok(loggedOut, "expected a claim for logged-out worker");
|
|
154
|
-
assert.equal(loggedOut.uniqueId, "follow-tier2");
|
|
155
|
-
} finally {
|
|
156
|
-
closeStoreDb();
|
|
157
|
-
cleanupTempDir(dir);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
async function testWatchHttpEndpoints() {
|
|
162
|
-
const { dir, dbPath } = createTempDbPath("tt-watch-http");
|
|
163
|
-
let server;
|
|
164
|
-
try {
|
|
165
|
-
const store = createStore(dbPath);
|
|
166
|
-
seedWatchStore(store);
|
|
167
|
-
|
|
168
|
-
const started = await startWatchServer(dbPath, 0, store);
|
|
169
|
-
server = started.server;
|
|
170
|
-
const actualPort = server.address().port;
|
|
171
|
-
const baseUrl = `http://127.0.0.1:${actualPort}`;
|
|
172
|
-
|
|
173
|
-
const [statsRes, usersRes, targetRes, lightUsersRes] = await Promise.all([
|
|
174
|
-
fetch(`${baseUrl}/api/stats`),
|
|
175
|
-
fetch(`${baseUrl}/api/users?limit=3`),
|
|
176
|
-
fetch(`${baseUrl}/api/target-users`),
|
|
177
|
-
fetch(`${baseUrl}/api/users?limit=2&view=light`),
|
|
178
|
-
]);
|
|
179
|
-
|
|
180
|
-
assert.equal(statsRes.status, 200);
|
|
181
|
-
assert.equal(usersRes.status, 200);
|
|
182
|
-
assert.equal(targetRes.status, 200);
|
|
183
|
-
assert.equal(lightUsersRes.status, 200);
|
|
184
|
-
|
|
185
|
-
const [stats, users, targets, lightUsers] = await Promise.all([
|
|
186
|
-
statsRes.json(),
|
|
187
|
-
usersRes.json(),
|
|
188
|
-
targetRes.json(),
|
|
189
|
-
lightUsersRes.json(),
|
|
190
|
-
]);
|
|
191
|
-
|
|
192
|
-
assert.equal(stats.totalUsers, 7);
|
|
193
|
-
assert.equal(stats.pendingUsers, 4);
|
|
194
|
-
assert.equal(stats.processedUsers, 1);
|
|
195
|
-
assert.equal(stats.restrictedUsers, 1);
|
|
196
|
-
assert.equal(stats.errorUsers, 1);
|
|
197
|
-
assert.equal(stats.targetUsers, 2);
|
|
198
|
-
assert.equal(stats.userUpdateTasks, 1);
|
|
199
|
-
assert.ok(Array.isArray(stats.countryStats));
|
|
200
|
-
assert.ok(stats.countryStats.some((item) => item.country === "ES"));
|
|
201
|
-
|
|
202
|
-
assert.equal(users.total, 7);
|
|
203
|
-
assert.equal(users.users.length, 3);
|
|
204
|
-
assert.equal(users.users[0].uniqueId, "seller-target");
|
|
205
|
-
|
|
206
|
-
assert.equal(targets.total, 2);
|
|
207
|
-
assert.deepEqual(
|
|
208
|
-
targets.users.map((item) => item.uniqueId),
|
|
209
|
-
["done-es", "seller-target"],
|
|
210
|
-
);
|
|
211
|
-
|
|
212
|
-
assert.equal(lightUsers.total, 7);
|
|
213
|
-
assert.equal(lightUsers.users.length, 2);
|
|
214
|
-
assert.deepEqual(Object.keys(lightUsers.users[0]).sort(), [
|
|
215
|
-
"followerCount",
|
|
216
|
-
"guessedLocation",
|
|
217
|
-
"locationCreated",
|
|
218
|
-
"nickname",
|
|
219
|
-
"pinned",
|
|
220
|
-
"processedAt",
|
|
221
|
-
"sources",
|
|
222
|
-
"status",
|
|
223
|
-
"ttSeller",
|
|
224
|
-
"uniqueId",
|
|
225
|
-
"verified",
|
|
226
|
-
]);
|
|
227
|
-
} finally {
|
|
228
|
-
if (server) {
|
|
229
|
-
await new Promise((resolve) => server.close(resolve));
|
|
230
|
-
}
|
|
231
|
-
closeStoreDb();
|
|
232
|
-
cleanupTempDir(dir);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
async function main() {
|
|
237
|
-
await testClaimPriorityAndRenewal();
|
|
238
|
-
await testWatchHttpEndpoints();
|
|
239
|
-
console.log("watch db smoke test passed");
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
main().catch((error) => {
|
|
243
|
-
console.error("watch db smoke test failed");
|
|
244
|
-
console.error(error);
|
|
245
|
-
process.exitCode = 1;
|
|
246
|
-
});
|