diff --git a/packages/client/api.yaml b/packages/client/api.yaml index fde2ca9be..58ff9c040 100644 --- a/packages/client/api.yaml +++ b/packages/client/api.yaml @@ -706,10 +706,8 @@ components: type: string GroupTopic: allOf: - - $ref: '#/components/schemas/TopicBase' + - $ref: '#/components/schemas/Topic' - properties: - creator: - $ref: '#/components/schemas/SlimUser' group: $ref: '#/components/schemas/SlimGroup' replies: @@ -717,7 +715,6 @@ components: $ref: '#/components/schemas/Reply' type: array required: - - creator - group - replies type: object @@ -2213,10 +2210,8 @@ components: type: object SubjectTopic: allOf: - - $ref: '#/components/schemas/TopicBase' + - $ref: '#/components/schemas/Topic' - properties: - creator: - $ref: '#/components/schemas/SlimUser' replies: items: $ref: '#/components/schemas/Reply' @@ -2224,7 +2219,6 @@ components: subject: $ref: '#/components/schemas/SlimSubject' required: - - creator - subject - replies type: object @@ -2509,22 +2503,12 @@ components: modelAsString: false name: TimelineSource Topic: - allOf: - - $ref: '#/components/schemas/TopicBase' - - properties: - creator: - $ref: '#/components/schemas/SlimUser' - replies: - type: integer - required: - - replies - type: object - title: Topic - TopicBase: properties: createdAt: description: 发帖时间,unix time stamp in seconds type: integer + creator: + $ref: '#/components/schemas/SlimUser' creatorID: type: integer display: @@ -2534,6 +2518,8 @@ components: parentID: description: 小组/条目ID type: integer + replyCount: + type: integer state: type: integer title: @@ -2546,11 +2532,12 @@ components: - title - creatorID - parentID + - replyCount - createdAt - updatedAt - state - display - title: TopicBase + title: Topic type: object TrendingSubject: properties: @@ -4517,6 +4504,23 @@ paths: default: 0 type: integer responses: + '200': + content: + application/json: + schema: + properties: + data: + items: + $ref: '#/components/schemas/GroupTopic' + type: array + total: + description: limit+offset 为参数的请求表示总条数,page 为参数的请求表示总页数 + type: integer + required: + - data + - total + type: object + description: Default Response '500': content: application/json: @@ -5865,6 +5869,58 @@ paths: summary: 编辑条目讨论回复 tags: - topic + /p1/subjects/-/topics: + get: + operationId: getRecentSubjectTopics + parameters: + - description: max 100 + in: query + name: limit + required: false + schema: + default: 20 + maximum: 100 + minimum: 1 + type: integer + - description: min 0 + in: query + name: offset + required: false + schema: + default: 0 + minimum: 0 + type: integer + responses: + '200': + content: + application/json: + schema: + properties: + data: + items: + $ref: '#/components/schemas/SubjectTopic' + type: array + total: + description: limit+offset 为参数的请求表示总条数,page 为参数的请求表示总页数 + type: integer + required: + - data + - total + type: object + description: Default Response + '500': + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + description: 意料之外的服务器错误 + description: 意料之外的服务器错误 + security: + - CookiesSession: [] + HTTPBearer: [] + summary: 获取最新的条目讨论 + tags: + - subject /p1/subjects/-/topics/{topicID}: get: operationId: getSubjectTopic diff --git a/packages/client/client.ts b/packages/client/client.ts index e994ebd97..2d408b711 100644 --- a/packages/client/client.ts +++ b/packages/client/client.ts @@ -320,23 +320,21 @@ export type SlimGroup = { nsfw: boolean; title: string; }; -export type TopicBase = { +export type Topic = { /** 发帖时间,unix time stamp in seconds */ createdAt: number; + creator?: SlimUser; creatorID: number; display: number; id: number; /** 小组/条目ID */ parentID: number; + replyCount: number; state: number; title: string; /** 最后回复时间,unix time stamp in seconds */ updatedAt: number; }; -export type Topic = TopicBase & { - creator?: SlimUser; - replies: number; -}; export type Post = { content: string; createdAt: number; @@ -358,8 +356,7 @@ export type ReplyBase = { export type Reply = ReplyBase & { replies: ReplyBase[]; }; -export type GroupTopic = TopicBase & { - creator: SlimUser; +export type GroupTopic = Topic & { group: SlimGroup; replies: Reply[]; }; @@ -509,8 +506,7 @@ export type SearchSubject = { keyword: string; sort?: SubjectSearchSort; }; -export type SubjectTopic = TopicBase & { - creator: SlimUser; +export type SubjectTopic = Topic & { replies: Reply[]; subject: SlimSubject; }; @@ -1835,10 +1831,20 @@ export function getRecentGroupTopics( } = {}, opts?: Oazapfts.RequestOpts, ) { - return oazapfts.fetchJson<{ - status: 500; - data: ErrorResponse; - }>( + return oazapfts.fetchJson< + | { + status: 200; + data: { + data: GroupTopic[]; + /** limit+offset 为参数的请求表示总条数,page 为参数的请求表示总页数 */ + total: number; + }; + } + | { + status: 500; + data: ErrorResponse; + } + >( `/p1/groups/-/topics${QS.query( QS.explode({ mode, @@ -2682,6 +2688,44 @@ export function editSubjectPost( }), ); } +/** + * 获取最新的条目讨论 + */ +export function getRecentSubjectTopics( + { + limit, + offset, + }: { + limit?: number; + offset?: number; + } = {}, + opts?: Oazapfts.RequestOpts, +) { + return oazapfts.fetchJson< + | { + status: 200; + data: { + data: SubjectTopic[]; + /** limit+offset 为参数的请求表示总条数,page 为参数的请求表示总页数 */ + total: number; + }; + } + | { + status: 500; + data: ErrorResponse; + } + >( + `/p1/subjects/-/topics${QS.query( + QS.explode({ + limit, + offset, + }), + )}`, + { + ...opts, + }, + ); +} /** * 获取条目讨论详情 */ diff --git a/packages/client/types/index.ts b/packages/client/types/index.ts index 65c71df3d..699ab8a97 100644 --- a/packages/client/types/index.ts +++ b/packages/client/types/index.ts @@ -860,6 +860,23 @@ export interface paths { patch?: never; trace?: never; }; + '/p1/subjects/-/topics': { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + /** 获取最新的条目讨论 */ + get: operations['getRecentSubjectTopics']; + put?: never; + post?: never; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; '/p1/subjects/-/topics/{topicID}': { parameters: { query?: never; @@ -1860,8 +1877,7 @@ export interface components { */ GroupSort: 'posts' | 'topics' | 'members' | 'created' | 'updated'; /** GroupTopic */ - GroupTopic: components['schemas']['TopicBase'] & { - creator: components['schemas']['SlimUser']; + GroupTopic: components['schemas']['Topic'] & { group: components['schemas']['SlimGroup']; replies: components['schemas']['Reply'][]; }; @@ -2597,8 +2613,7 @@ export interface components { name: string; }; /** SubjectTopic */ - SubjectTopic: components['schemas']['TopicBase'] & { - creator: components['schemas']['SlimUser']; + SubjectTopic: components['schemas']['Topic'] & { replies: components['schemas']['Reply'][]; subject: components['schemas']['SlimSubject']; }; @@ -2715,19 +2730,16 @@ export interface components { */ TimelineSource: 0 | 1 | 2 | 3 | 4 | 5; /** Topic */ - Topic: components['schemas']['TopicBase'] & { - creator?: components['schemas']['SlimUser']; - replies: number; - }; - /** TopicBase */ - TopicBase: { + Topic: { /** @description 发帖时间,unix time stamp in seconds */ createdAt: number; + creator?: components['schemas']['SlimUser']; creatorID: number; display: number; id: number; /** @description 小组/条目ID */ parentID: number; + replyCount: number; state: number; title: string; /** @description 最后回复时间,unix time stamp in seconds */ @@ -4276,6 +4288,19 @@ export interface operations { }; requestBody?: never; responses: { + /** @description Default Response */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + 'application/json': { + data: components['schemas']['GroupTopic'][]; + /** @description limit+offset 为参数的请求表示总条数,page 为参数的请求表示总页数 */ + total: number; + }; + }; + }; /** @description 意料之外的服务器错误 */ 500: { headers: { @@ -5358,6 +5383,44 @@ export interface operations { }; }; }; + getRecentSubjectTopics: { + parameters: { + query?: { + /** @description max 100 */ + limit?: number; + /** @description min 0 */ + offset?: number; + }; + header?: never; + path?: never; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description Default Response */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + 'application/json': { + data: components['schemas']['SubjectTopic'][]; + /** @description limit+offset 为参数的请求表示总条数,page 为参数的请求表示总页数 */ + total: number; + }; + }; + }; + /** @description 意料之外的服务器错误 */ + 500: { + headers: { + [name: string]: unknown; + }; + content: { + 'application/json': components['schemas']['ErrorResponse']; + }; + }; + }; + }; getSubjectTopic: { parameters: { query?: never; diff --git a/packages/website/src/pages/index/group/[name]/__tests__/fixtures/recent-topics.json b/packages/website/src/pages/index/group/[name]/__tests__/fixtures/recent-topics.json index 5fdbe2f12..6711d3b5b 100644 --- a/packages/website/src/pages/index/group/[name]/__tests__/fixtures/recent-topics.json +++ b/packages/website/src/pages/index/group/[name]/__tests__/fixtures/recent-topics.json @@ -9,7 +9,7 @@ "updatedAt": 1662283112, "state": 2, "display": 1, - "replies": 2, + "replyCount": 2, "creator": { "id": 287622, "username": "trim21", @@ -32,7 +32,7 @@ "updatedAt": 1687677475, "state": 0, "display": 1, - "replies": 41, + "replyCount": 41, "creator": { "id": 287622, "username": "trim21", diff --git a/packages/website/src/pages/index/group/[name]/components/TopicsTable.tsx b/packages/website/src/pages/index/group/[name]/components/TopicsTable.tsx index de2e52b51..4f535cbd6 100644 --- a/packages/website/src/pages/index/group/[name]/components/TopicsTable.tsx +++ b/packages/website/src/pages/index/group/[name]/components/TopicsTable.tsx @@ -36,7 +36,7 @@ const TopicsTable: React.FC<{ topics: Topic[] }> = ({ topics }) => { {topic.creator?.nickname} -