fix(route/zsxq): 优化问答型消息可读性 (#16550)

* fix(route/zsxq): 优化问答型消息可读性

* fix(route/zsxq): unexpected any type

* fix(route/zsxq): Handling of questions from anonymous users
This commit is contained in:
Raspberry
2024-08-27 21:29:13 +08:00
committed by GitHub
parent 183fce012e
commit 5fd5b80fdc
2 changed files with 13 additions and 3 deletions
+9
View File
@@ -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<UserInfo>;
export type GroupInfoResponse = BasicResponse<GroupInfo>;
+4 -3
View File
@@ -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<T extends BasicResponse<any>>(path: string, retryCount = 0): Promise<T['resp_data']> {
export async function customFetch<T extends BasicResponse<ResponseData>>(path: string, retryCount = 0): Promise<T['resp_data']> {
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 = `<blockquote>${String(topic.question?.owner?.name ?? '匿名用户')} 提问:${description}</blockquote>`;
if (topic.answered) {
description += '<br><br>';
description += '<br>' + topic.answer?.owner.name + ' 回答:<br><br>';
description += parseTopicContent(topic.answer?.text, topic.answer?.images);
}
break;