From 5fd5b80fdcc794cb112ac993bf015608e3fafea9 Mon Sep 17 00:00:00 2001 From: Raspberry <25424627+yana9i@users.noreply.github.com> Date: Tue, 27 Aug 2024 21:29:13 +0800 Subject: [PATCH] =?UTF-8?q?fix(route/zsxq):=20=E4=BC=98=E5=8C=96=E9=97=AE?= =?UTF-8?q?=E7=AD=94=E5=9E=8B=E6=B6=88=E6=81=AF=E5=8F=AF=E8=AF=BB=E6=80=A7?= =?UTF-8?q?=20(#16550)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(route/zsxq): 优化问答型消息可读性 * fix(route/zsxq): unexpected any type * fix(route/zsxq): Handling of questions from anonymous users --- lib/routes/zsxq/types.ts | 9 +++++++++ lib/routes/zsxq/utils.ts | 7 ++++--- 2 files changed, 13 insertions(+), 3 deletions(-) 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;