|
@@ -8,7 +8,7 @@ import type {
|
|
|
PlatformType,
|
|
PlatformType,
|
|
|
} from '@media-manager/shared';
|
|
} from '@media-manager/shared';
|
|
|
import { wsManager } from '../websocket/index.js';
|
|
import { wsManager } from '../websocket/index.js';
|
|
|
-import { headlessBrowserService, type WorkComments, type CookieData } from './HeadlessBrowserService.js';
|
|
|
|
|
|
|
+import { headlessBrowserService, type CookieData } from './HeadlessBrowserService.js';
|
|
|
import { CookieManager } from '../automation/cookie.js';
|
|
import { CookieManager } from '../automation/cookie.js';
|
|
|
import { logger } from '../utils/logger.js';
|
|
import { logger } from '../utils/logger.js';
|
|
|
|
|
|
|
@@ -210,7 +210,7 @@ export class CommentService {
|
|
|
const accountRepository = AppDataSource.getRepository(PlatformAccount);
|
|
const accountRepository = AppDataSource.getRepository(PlatformAccount);
|
|
|
|
|
|
|
|
// 获取需要同步的账号列表
|
|
// 获取需要同步的账号列表
|
|
|
- const whereCondition: { userId: number; id?: number; platform?: string } = { userId };
|
|
|
|
|
|
|
+ const whereCondition: { userId: number; id?: number; platform?: PlatformType } = { userId };
|
|
|
if (accountId) {
|
|
if (accountId) {
|
|
|
whereCondition.id = accountId;
|
|
whereCondition.id = accountId;
|
|
|
}
|
|
}
|
|
@@ -227,7 +227,7 @@ export class CommentService {
|
|
|
for (const account of accounts) {
|
|
for (const account of accounts) {
|
|
|
try {
|
|
try {
|
|
|
// 只处理支持的平台
|
|
// 只处理支持的平台
|
|
|
- if (account.platform !== 'douyin' && account.platform !== 'xiaohongshu' && account.platform !== 'weixin_video') {
|
|
|
|
|
|
|
+ if (account.platform !== 'douyin' && account.platform !== 'xiaohongshu' && account.platform !== 'weixin_video' && account.platform !== 'baijiahao') {
|
|
|
logger.info(`Skipping unsupported platform: ${account.platform}`);
|
|
logger.info(`Skipping unsupported platform: ${account.platform}`);
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
@@ -282,6 +282,8 @@ export class CommentService {
|
|
|
workComments = await headlessBrowserService.fetchXiaohongshuCommentsViaApi(cookies);
|
|
workComments = await headlessBrowserService.fetchXiaohongshuCommentsViaApi(cookies);
|
|
|
} else if (account.platform === 'weixin_video') {
|
|
} else if (account.platform === 'weixin_video') {
|
|
|
workComments = await headlessBrowserService.fetchWeixinVideoCommentsViaApi(cookies);
|
|
workComments = await headlessBrowserService.fetchWeixinVideoCommentsViaApi(cookies);
|
|
|
|
|
+ } else if (account.platform === 'baijiahao') {
|
|
|
|
|
+ workComments = await headlessBrowserService.fetchBaijiahaoCommentsViaApi(cookies);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -303,7 +305,9 @@ export class CommentService {
|
|
|
for (const work of accountWorks) {
|
|
for (const work of accountWorks) {
|
|
|
if (work.platformVideoId) {
|
|
if (work.platformVideoId) {
|
|
|
videoIdToWorkMap.set(work.platformVideoId, { id: work.id, title: work.title });
|
|
videoIdToWorkMap.set(work.platformVideoId, { id: work.id, title: work.title });
|
|
|
- // 同时存储不带前缀的版本(如果 platformVideoId 是 "douyin_xxx" 格式)
|
|
|
|
|
|
|
+ // 同时存储带平台前缀的版本(兼容 comment.videoId 为 "platform_xxx" 的情况)
|
|
|
|
|
+ videoIdToWorkMap.set(`${work.platform}_${work.platformVideoId}`, { id: work.id, title: work.title });
|
|
|
|
|
+ // 同时存储不带前缀的版本(如果 platformVideoId 是 "platform_xxx" 格式)
|
|
|
if (work.platformVideoId.includes('_')) {
|
|
if (work.platformVideoId.includes('_')) {
|
|
|
const parts = work.platformVideoId.split('_');
|
|
const parts = work.platformVideoId.split('_');
|
|
|
if (parts.length >= 2) {
|
|
if (parts.length >= 2) {
|
|
@@ -340,7 +344,7 @@ export class CommentService {
|
|
|
|
|
|
|
|
// 尝试带平台前缀匹配
|
|
// 尝试带平台前缀匹配
|
|
|
if (!workId) {
|
|
if (!workId) {
|
|
|
- const prefixedId = `douyin_${commentVideoId}`;
|
|
|
|
|
|
|
+ const prefixedId = `${account.platform}_${commentVideoId}`;
|
|
|
if (videoIdToWorkMap.has(prefixedId)) {
|
|
if (videoIdToWorkMap.has(prefixedId)) {
|
|
|
const matched = videoIdToWorkMap.get(prefixedId)!;
|
|
const matched = videoIdToWorkMap.get(prefixedId)!;
|
|
|
workId = matched.id;
|
|
workId = matched.id;
|
|
@@ -354,7 +358,7 @@ export class CommentService {
|
|
|
if (!w.platformVideoId) return false;
|
|
if (!w.platformVideoId) return false;
|
|
|
// 尝试各种匹配方式
|
|
// 尝试各种匹配方式
|
|
|
return w.platformVideoId === commentVideoId ||
|
|
return w.platformVideoId === commentVideoId ||
|
|
|
- w.platformVideoId === `douyin_${commentVideoId}` ||
|
|
|
|
|
|
|
+ w.platformVideoId === `${account.platform}_${commentVideoId}` ||
|
|
|
w.platformVideoId.endsWith(`_${commentVideoId}`) ||
|
|
w.platformVideoId.endsWith(`_${commentVideoId}`) ||
|
|
|
w.platformVideoId.includes(commentVideoId);
|
|
w.platformVideoId.includes(commentVideoId);
|
|
|
});
|
|
});
|
|
@@ -518,16 +522,21 @@ export class CommentService {
|
|
|
if (work.platformVideoId) {
|
|
if (work.platformVideoId) {
|
|
|
// 存储原始 platformVideoId
|
|
// 存储原始 platformVideoId
|
|
|
videoIdToWork.set(work.platformVideoId, { id: work.id, title: work.title });
|
|
videoIdToWork.set(work.platformVideoId, { id: work.id, title: work.title });
|
|
|
|
|
+ // 存储带平台前缀的版本
|
|
|
|
|
+ videoIdToWork.set(`${work.platform}_${work.platformVideoId}`, { id: work.id, title: work.title });
|
|
|
|
|
|
|
|
- // 如果是 "douyin_xxx" 格式,也存储纯 ID
|
|
|
|
|
- if (work.platformVideoId.startsWith('douyin_')) {
|
|
|
|
|
- const pureId = work.platformVideoId.replace('douyin_', '');
|
|
|
|
|
- videoIdToWork.set(pureId, { id: work.id, title: work.title });
|
|
|
|
|
|
|
+ // 如果是 "platform_xxx" 格式,也存储纯 ID
|
|
|
|
|
+ if (work.platformVideoId.includes('_')) {
|
|
|
|
|
+ const parts = work.platformVideoId.split('_');
|
|
|
|
|
+ if (parts.length >= 2) {
|
|
|
|
|
+ const pureId = parts.slice(1).join('_');
|
|
|
|
|
+ videoIdToWork.set(pureId, { id: work.id, title: work.title });
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 如果是纯数字 ID,也存储带前缀的版本
|
|
// 如果是纯数字 ID,也存储带前缀的版本
|
|
|
if (/^\d+$/.test(work.platformVideoId)) {
|
|
if (/^\d+$/.test(work.platformVideoId)) {
|
|
|
- videoIdToWork.set(`douyin_${work.platformVideoId}`, { id: work.id, title: work.title });
|
|
|
|
|
|
|
+ videoIdToWork.set(`${work.platform}_${work.platformVideoId}`, { id: work.id, title: work.title });
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -544,7 +553,7 @@ export class CommentService {
|
|
|
}
|
|
}
|
|
|
// 尝试带前缀匹配
|
|
// 尝试带前缀匹配
|
|
|
if (!matchedWorkId) {
|
|
if (!matchedWorkId) {
|
|
|
- const prefixedId = `douyin_${comment.videoId}`;
|
|
|
|
|
|
|
+ const prefixedId = `${comment.platform}_${comment.videoId}`;
|
|
|
if (videoIdToWork.has(prefixedId)) {
|
|
if (videoIdToWork.has(prefixedId)) {
|
|
|
matchedWorkId = videoIdToWork.get(prefixedId)!.id;
|
|
matchedWorkId = videoIdToWork.get(prefixedId)!.id;
|
|
|
}
|
|
}
|