|
|
@@ -285,7 +285,7 @@ function findArrayWithDateLikeField(root: any): { arr: any[]; dateKey: string }
|
|
|
const s = String(v).trim();
|
|
|
return /^\d{8}$/.test(s) || /^\d{4}[-/]\d{1,2}[-/]\d{1,2}$/.test(s);
|
|
|
};
|
|
|
- const dateKeyCandidates = ['day', 'date', 'stat_day', 'statDay', 'dt', 'time', 'the_day'];
|
|
|
+ const dateKeyCandidates = ['event_day', 'day', 'date', 'stat_day', 'statDay', 'dt', 'time', 'the_day'];
|
|
|
const candidates: Array<{ arr: any[]; dateKey: string }> = [];
|
|
|
|
|
|
while (queue.length) {
|
|
|
@@ -356,24 +356,24 @@ function parseBaijiahaoAppStatisticV3(json: any): Map<string, { recordDate: Date
|
|
|
if (!result.has(key)) result.set(key, { recordDate: d });
|
|
|
const obj = result.get(key)!;
|
|
|
|
|
|
- // 阅读量 → playCount
|
|
|
- const play = pickNumber(item, ['read_cnt', 'readCount', 'read', 'pv', 'view_cnt', 'viewCount', 'views']);
|
|
|
+ // 阅读量 → playCount(百家号 appStatisticV3 使用 view_count)
|
|
|
+ const play = pickNumber(item, ['view_count', 'read_cnt', 'readCount', 'read', 'pv', 'view_cnt', 'viewCount', 'views']);
|
|
|
if (typeof play === 'number') (obj as any).playCount = play;
|
|
|
|
|
|
- // 点赞量 → likeCount
|
|
|
- const like = pickNumber(item, ['like_cnt', 'praise_cnt', 'praise', 'likeCount', 'likes']);
|
|
|
+ // 点赞量 → likeCount(百家号 API 使用 likes_count)
|
|
|
+ const like = pickNumber(item, ['likes_count', 'like_cnt', 'praise_cnt', 'praise', 'likeCount', 'likes']);
|
|
|
if (typeof like === 'number') (obj as any).likeCount = like;
|
|
|
|
|
|
- // 评论量 → commentCount
|
|
|
- const comment = pickNumber(item, ['comment_cnt', 'commentCount', 'comments']);
|
|
|
+ // 评论量 → commentCount(百家号 API 使用 comment_count)
|
|
|
+ const comment = pickNumber(item, ['comment_count', 'comment_cnt', 'commentCount', 'comments']);
|
|
|
if (typeof comment === 'number') (obj as any).commentCount = comment;
|
|
|
|
|
|
- // 收藏量 → collectCount
|
|
|
- const collect = pickNumber(item, ['collect_cnt', 'favorite_cnt', 'fav_cnt', 'collectCount', 'favorites']);
|
|
|
+ // 收藏量 → collectCount(百家号 API 字段为 collect_count)
|
|
|
+ const collect = pickNumber(item, ['collect_count', 'collect_cnt', 'favorite_cnt', 'fav_cnt', 'collectCount', 'favorites']);
|
|
|
if (typeof collect === 'number') (obj as any).collectCount = collect;
|
|
|
|
|
|
- // 分享量 → shareCount
|
|
|
- const share = pickNumber(item, ['share_cnt', 'shareCount', 'shares']);
|
|
|
+ // 分享量 → shareCount(百家号 API 使用 share_count)
|
|
|
+ const share = pickNumber(item, ['share_count', 'share_cnt', 'shareCount', 'shares']);
|
|
|
if (typeof share === 'number') (obj as any).shareCount = share;
|
|
|
|
|
|
// 点击率 → coverClickRate
|
|
|
@@ -385,8 +385,8 @@ function parseBaijiahaoAppStatisticV3(json: any): Map<string, { recordDate: Date
|
|
|
const clickRate = formatPercentString(clickRateRaw);
|
|
|
if (clickRate) (obj as any).coverClickRate = clickRate;
|
|
|
|
|
|
- // 作品涨粉量 → fansIncrease(只取涨粉)
|
|
|
- const fansInc = pickNumber(item, ['works_fans_inc', 'worksFansInc', 'content_fans_inc', 'fans_inc', 'fansIncrease']);
|
|
|
+ // 作品涨粉量 → fansIncrease(百家号 API 使用 fans_increase / fans_add_cnt)
|
|
|
+ const fansInc = pickNumber(item, ['fans_increase', 'fans_add_cnt', 'works_fans_inc', 'worksFansInc', 'content_fans_inc', 'fans_inc', 'fansIncrease']);
|
|
|
if (typeof fansInc === 'number') (obj as any).fansIncrease = fansInc;
|
|
|
}
|
|
|
|
|
|
@@ -632,8 +632,26 @@ export class BaijiahaoContentOverviewImportService {
|
|
|
}
|
|
|
const json = await res.json().catch(() => null);
|
|
|
if (!json) throw new Error('appStatisticV3 json parse failed');
|
|
|
+
|
|
|
+ // 调试:BJ_IMPORT_DEBUG=1 时把接口原始返回写入文件,便于对比
|
|
|
+ if (process.env.BJ_IMPORT_DEBUG === '1') {
|
|
|
+ const debugPath = path.join(this.downloadDir, `appStatisticV3_response_${account.id}_${Date.now()}.json`);
|
|
|
+ await ensureDir(this.downloadDir);
|
|
|
+ await fs.writeFile(debugPath, JSON.stringify(json, null, 2), 'utf-8');
|
|
|
+ logger.info(`[BJ Import] DEBUG: appStatisticV3 原始响应已写入 ${debugPath}`);
|
|
|
+ }
|
|
|
+
|
|
|
const map = parseBaijiahaoAppStatisticV3(json);
|
|
|
logger.info(`[BJ Import] appStatisticV3 fetched. accountId=${account.id} days=${map.size} range=${start_day}-${end_day}`);
|
|
|
+
|
|
|
+ // 调试:打印解析后指定日期的数据(如 2026-02-02)便于对比
|
|
|
+ if (process.env.BJ_IMPORT_DEBUG === '1' && map.size > 0) {
|
|
|
+ const sampleKeys = ['2026-02-02', '2026-02-01', '2026-01-16'];
|
|
|
+ for (const k of sampleKeys) {
|
|
|
+ const v = map.get(k);
|
|
|
+ if (v) logger.info(`[BJ Import] DEBUG: 解析后 ${k} => ${JSON.stringify(v)}`);
|
|
|
+ }
|
|
|
+ }
|
|
|
return map;
|
|
|
};
|
|
|
|