Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/clis/xiaohongshu/user-helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,41 @@ describe('extractXhsUserNotes', () => {
title: 'First note',
type: 'video',
likes: '4.6万',
cover: '',
url: 'https://www.xiaohongshu.com/user/profile/user-1/note-1?xsec_token=abc&xsec_source=pc_user',
},
{
id: 'note-2',
title: 'Second note',
type: 'normal',
likes: '42',
cover: '',
url: 'https://www.xiaohongshu.com/user/profile/fallback-user/note-2',
},
]);
});

it('extracts cover urls with fallback priority urlDefault -> urlPre -> url', () => {
const rows = extractXhsUserNotes(
{
noteGroups: [
[
{ noteCard: { noteId: 'cover-1', cover: { urlDefault: 'https://img.example/default.jpg', urlPre: 'https://img.example/pre.jpg', url: 'https://img.example/raw.jpg' } } },
{ noteCard: { noteId: 'cover-2', cover: { urlPre: 'https://img.example/pre-only.jpg', url: 'https://img.example/raw-only.jpg' } } },
{ noteCard: { noteId: 'cover-3', cover: { url: 'https://img.example/raw-fallback.jpg' } } },
],
],
},
'fallback-user'
);

expect(rows.map(row => row.cover)).toEqual([
'https://img.example/default.jpg',
'https://img.example/pre-only.jpg',
'https://img.example/raw-fallback.jpg',
]);
});

it('deduplicates repeated notes by note id', () => {
const rows = extractXhsUserNotes(
{
Expand Down
4 changes: 4 additions & 0 deletions src/clis/xiaohongshu/user-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface XhsUserNoteRow {
title: string;
type: string;
likes: string;
cover: string;
url: string;
}

Expand Down Expand Up @@ -72,11 +73,14 @@ export function extractXhsUserNotes(snapshot: XhsUserPageSnapshot, fallbackUserI
const xsecToken = toCleanString(entry?.xsecToken ?? entry?.xsec_token ?? noteCard.xsecToken ?? noteCard.xsec_token);
const likes = toCleanString(noteCard.interactInfo?.likedCount ?? noteCard.interact_info?.liked_count ?? 0) || '0';

const cover = toCleanString(noteCard.cover?.urlDefault ?? noteCard.cover?.urlPre ?? noteCard.cover?.url ?? '');

rows.push({
id: noteId,
title: toCleanString(noteCard.displayTitle ?? noteCard.display_title ?? noteCard.title),
type: toCleanString(noteCard.type),
likes,
cover,
url: buildXhsNoteUrl(userId || fallbackUserId, noteId, xsecToken),
});
}
Expand Down