Skip to content
Open
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
6 changes: 3 additions & 3 deletions lib/routes/zsxq/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface BasicTopic {
create_time: string;
digested: boolean;
group: {
group_id: number;
group_id: number | string;
name: string;
type: string;
background_url: string;
Expand All @@ -22,14 +22,14 @@ interface BasicTopic {
avatar_url: string;
name: string;
number: number;
user_id: number;
user_id: number | string;
};
}>;
likes_count: number;
readers_count: number;
reading_count: number;
rewards_count: number;
topic_id: number;
topic_id: number | string;
type: string;
user_specific: {
liked: false;
Expand Down
8 changes: 6 additions & 2 deletions lib/routes/zsxq/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ export async function customFetch<T extends BasicResponse<ResponseData>>(path: s
headers: {
cookie: `zsxq_access_token=${config.zsxq.accessToken};`,
},
responseType: 'text',
});
const { succeeded, code, resp_data } = response.data as T;
// Preserve large integer IDs (topic_id, group_id, user_id etc.) by converting them to strings
// before JSON.parse, which would otherwise lose precision on numbers > Number.MAX_SAFE_INTEGER
const safeBody = (response.body as string).replaceAll(/("(?:topic_id|group_id|user_id|task_id|image_id|category_id)"\s*:\s*)(\d+)/g, '$1"$2"');
const { succeeded, code, resp_data } = JSON.parse(safeBody) as T;
Comment on lines +19 to +20
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use json-bigint instead.

if (succeeded) {
return resp_data;
}
Expand All @@ -39,7 +43,7 @@ export function generateTopicDataItem(topics: Topic[]): DataItem[] {
return topics.map((topic) => {
let description: string | undefined;
let title = '';
const url = `https://wx.zsxq.com/topic/${topic.topic_id}`;
const url = `https://wx.zsxq.com/group/${topic.group.group_id}/topic/${topic.topic_id}`;
switch (topic.type) {
case 'talk':
title = topic.talk?.text?.split('\n')[0] ?? '文章';
Expand Down
Loading