|
@@ -716,7 +716,8 @@ class HeadlessBrowserService {
|
|
|
const cookieString = JSON.stringify(cookies);
|
|
const cookieString = JSON.stringify(cookies);
|
|
|
const pythonPlatform = platform === 'weixin_video' ? 'weixin' : platform;
|
|
const pythonPlatform = platform === 'weixin_video' ? 'weixin' : platform;
|
|
|
|
|
|
|
|
- const pageSize = platform === 'xiaohongshu' ? 20 : 50;
|
|
|
|
|
|
|
+ // 抖音 work_list 接口 count 最大 20,需与创作者中心一致
|
|
|
|
|
+ const pageSize = platform === 'xiaohongshu' ? 20 : platform === 'douyin' ? 20 : 50;
|
|
|
let maxPages = 30;
|
|
let maxPages = 30;
|
|
|
const allWorks: WorkItem[] = [];
|
|
const allWorks: WorkItem[] = [];
|
|
|
const seenIds = new Set<string>();
|
|
const seenIds = new Set<string>();
|
|
@@ -822,19 +823,25 @@ class HeadlessBrowserService {
|
|
|
|
|
|
|
|
if (useCursorPagination) {
|
|
if (useCursorPagination) {
|
|
|
const next = result.next_page;
|
|
const next = result.next_page;
|
|
|
- const expectedMore = declaredTotal && declaredTotal > 0 ? allWorks.length < declaredTotal : !!result.has_more;
|
|
|
|
|
|
|
+ const hasNextCursor = next !== undefined && next !== null && next !== '' && next !== -1 && next !== '-1';
|
|
|
|
|
|
|
|
- if (next !== undefined && next !== null && next !== '' && next !== -1 && next !== '-1') {
|
|
|
|
|
|
|
+ if (hasNextCursor) {
|
|
|
const key = String(next);
|
|
const key = String(next);
|
|
|
if (seenCursors.has(key)) break;
|
|
if (seenCursors.has(key)) break;
|
|
|
seenCursors.add(key);
|
|
seenCursors.add(key);
|
|
|
cursor = next;
|
|
cursor = next;
|
|
|
} else {
|
|
} else {
|
|
|
- if (platform === 'douyin' && (next === 0 || next === '0')) break;
|
|
|
|
|
|
|
+ if (platform === 'douyin') break;
|
|
|
cursor = (typeof cursor === 'number' ? cursor + 1 : pageIndex + 1);
|
|
cursor = (typeof cursor === 'number' ? cursor + 1 : pageIndex + 1);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (!expectedMore || pageWorks.length === 0 || newCount === 0) break;
|
|
|
|
|
|
|
+ // 抖音:仅当无下一页游标或本页 0 条时停止(不依赖 has_more/declaredTotal,避免只同步 20 条)
|
|
|
|
|
+ if (platform === 'douyin') {
|
|
|
|
|
+ if (!hasNextCursor || pageWorks.length === 0) break;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ const expectedMore = declaredTotal && declaredTotal > 0 ? allWorks.length < declaredTotal : !!result.has_more;
|
|
|
|
|
+ if (!expectedMore || pageWorks.length === 0 || newCount === 0) break;
|
|
|
|
|
+ }
|
|
|
} else {
|
|
} else {
|
|
|
if (!result.has_more || pageWorks.length === 0 || newCount === 0) break;
|
|
if (!result.has_more || pageWorks.length === 0 || newCount === 0) break;
|
|
|
}
|
|
}
|