diff --git a/lib/routes/zsxq/types.ts b/lib/routes/zsxq/types.ts index 5ec0851ce..cefce3504 100644 --- a/lib/routes/zsxq/types.ts +++ b/lib/routes/zsxq/types.ts @@ -63,6 +63,13 @@ export interface QATopic extends BasicTopic { question: { images?: TopicImage[]; text?: string; + owner?: { + avatar_url: string; + description: string; + location: string; + name: string; + user_id: number; + }; }; } @@ -140,6 +147,8 @@ export interface TopicImage { export type Topic = TalkTopic | QATopic | TaskTopic | SolutionTopic; +export type ResponseData = UserInfo | GroupInfo | Topic[]; + export type UserInfoResponse = BasicResponse; export type GroupInfoResponse = BasicResponse; diff --git a/lib/routes/zsxq/utils.ts b/lib/routes/zsxq/utils.ts index 7c659a07f..5e0a4e939 100644 --- a/lib/routes/zsxq/utils.ts +++ b/lib/routes/zsxq/utils.ts @@ -1,10 +1,10 @@ import got from '@/utils/got'; -import type { TopicImage, Topic, BasicResponse } from './types'; +import type { TopicImage, Topic, BasicResponse, ResponseData } from './types'; import { parseDate } from '@/utils/parse-date'; import { config } from '@/config'; import type { DataItem } from '@/types'; -export async function customFetch>(path: string, retryCount = 0): Promise { +export async function customFetch>(path: string, retryCount = 0): Promise { const apiUrl = 'https://api.zsxq.com/v2'; const response = await got(apiUrl + path, { @@ -46,8 +46,9 @@ export function generateTopicDataItem(topics: Topic[]): DataItem[] { case 'q&a': title = topic.question?.text?.split('\n')[0] ?? '问答'; description = parseTopicContent(topic.question?.text, topic.question?.images); + description = `
${String(topic.question?.owner?.name ?? '匿名用户')} 提问:${description}
`; if (topic.answered) { - description += '

'; + description += '
' + topic.answer?.owner.name + ' 回答:

'; description += parseTopicContent(topic.answer?.text, topic.answer?.images); } break;