Skip to content

Commit

Permalink
fix(route/zsxq): 优化问答型消息可读性 (DIYgod#16550)
Browse files Browse the repository at this point in the history
* fix(route/zsxq): 优化问答型消息可读性

* fix(route/zsxq): unexpected any type

* fix(route/zsxq): Handling of questions from anonymous users
  • Loading branch information
yana9i authored Aug 27, 2024
1 parent 183fce0 commit 5fd5b80
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 9 additions & 0 deletions lib/routes/zsxq/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};
}

Expand Down Expand Up @@ -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>;
Expand Down
7 changes: 4 additions & 3 deletions lib/routes/zsxq/utils.ts
Original file line number Diff line number Diff line change
@@ -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, {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 5fd5b80

Please sign in to comment.