Skip to content
Open
Changes from 1 commit
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
53 changes: 36 additions & 17 deletions lib/routes/xiaohongshu/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
import { ViewType } from '@/types';
import cache from '@/utils/cache';
import { fallback, queryToBoolean } from '@/utils/readable-social';

import { getUser, getUserWithCookie, renderNotesFulltext } from './util';

import { getFullNote, getUser, getUserWithCookie, renderNotesFulltext } from './util';

Check failure

Code scanning / oxlint

import-x-js(newline-after-import) Error

Expected 1 empty line after import statement not followed by another import.
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
export const route: Route = {
path: '/user/:user_id/:category/:routeParams?',
name: '用户笔记/收藏',
Expand Down Expand Up @@ -97,18 +95,39 @@
const description = `${basicInfo.desc} ${tags.map((t) => t.name).join(' ')} ${interactions.map((i) => `${i.count} ${i.name}`).join(' ')}`;
const image = basicInfo.imageb || basicInfo.images;

const renderNote = (notes) =>
notes.flatMap((n) =>
n.map(({ id, noteCard }) => ({
title: noteCard.displayTitle,
link: new URL(noteCard.noteId || id, url).toString(),
guid: noteCard.displayTitle,
description: `<img src="${noteCard.cover.infoList.pop().url}" width="${noteCard.cover.width}" height="${noteCard.cover.height}"><br>${noteCard.displayTitle}`,
author: noteCard.user.nickname,
upvotes: noteCard.interactInfo.likedCount,
}))
);
const renderCollect = (collect) => {
const urlNotePrefix = 'https://www.xiaohongshu.com/explore';
const renderNote = async (notes) => {

Check failure

Code scanning / oxlint

eslint(require-await) Error

Async function has no await expression.
Consider removing the async keyword.
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
const promises = notes.flatMap((n) =>
n.map(async ({ id, noteCard }) => {
const link = `${urlNotePrefix}/${id}`;
try {
const { title, description, pubDate, updated } = await getFullNote(link, false);
return {
title,
link,
description,
author: noteCard.user.nickname,
guid: `${urlNotePrefix}/${noteCard.noteId}`,
pubDate,
updated,
upvotes: noteCard.interactInfo.likedCount,
};
} catch {
// Fallback to basic rendering if full fetch fails
return {
title: noteCard.displayTitle,
link,
guid: noteCard.displayTitle,
description: `<img src="${noteCard.cover.infoList.pop().url}" width="${noteCard.cover.width}" height="${noteCard.cover.height}"><br>${noteCard.displayTitle}`,
author: noteCard.user.nickname,
upvotes: noteCard.interactInfo.likedCount,
};
}
})
);
return Promise.all(promises);
};
const renderCollect = (collect) => {
if (!collect) {
throw new InvalidParameterError('该用户已设置收藏内容不可见');
}
Expand All @@ -120,7 +139,7 @@
}
return collect.data.notes.map((item) => ({
title: item.display_title,
link: `${url}/${item.note_id}`,
link: `https://www.xiaohongshu.com/explore/${item.note_id}`,
description: `<img src ="${item.cover.info_list.pop().url}"><br>${item.display_title}`,
author: item.user.nickname,
upvotes: item.interact_info.likedCount,
Expand All @@ -132,6 +151,6 @@
description,
image,
link: url,
item: category === 'notes' ? renderNote(notes) : renderCollect(collect),
item: category === 'notes' ? await renderNote(notes) : renderCollect(collect),
};
}
Loading