| 1 | import { z } from 'zod' |
| 2 | import { createZodDto } from '../utils' |
| 3 | |
| 4 | export const KeysetPaginationSchema = z.object({ |
| 5 | before: z.string().nullish().describe('前一页游标'), |
| 6 | after: z.string().nullish().describe('后一页游标'), |
| 7 | limit: z.number().min(1).max(100).nullish().describe('每页数量,默认20'), |
| 8 | }) |
| 9 | |
| 10 | export const OffsetPaginationSchema = z.object({ |
| 11 | pageNo: z.number({ message: '页码' }).min(1).nullish().default(1).describe('页码,默认1'), |
| 12 | pageSize: z.number({ message: '每页数量' }).min(1).max(100).nullish().default(20).describe('每页数量,默认20'), |
| 13 | }) |
| 14 | |
| 15 | export const mediaSchema = z.object({ |
| 16 | url: z.string().describe('Media URL'), |
| 17 | type: z.enum(['image', 'video']).describe('Type of media'), |
| 18 | thumbnail: z.string().nullish().describe('Thumbnail URL for video media'), |
| 19 | }) |
| 20 | |
| 21 | export const postSchema = z.object({ |
| 22 | id: z.string().describe('Post ID'), |
| 23 | platform: z.string().describe('Platform of the post'), |
| 24 | title: z.string().nullish().describe('Title of the post'), |
| 25 | content: z.string().describe('Content of the post'), |
| 26 | medias: z.array(mediaSchema).describe('List of media associated with the post'), |
| 27 | permalink: z.string().describe('Permanent link to the post'), |
| 28 | publishTime: z.number().describe('Publish time in milliseconds since epoch'), |
| 29 | viewCount: z.number().describe('Number of views').default(0), |
| 30 | commentCount: z.number().describe('Number of comments').default(0), |
| 31 | likeCount: z.number().describe('Number of likes').default(0), |
| 32 | shareCount: z.number().describe('Number of shares').default(0), |
| 33 | clickCount: z.number().describe('Number of clicks').default(0), |
| 34 | impressionCount: z.number().describe('Number of impressions').default(0), |
| 35 | favoriteCount: z.number().describe('Number of favorites').default(0), |
| 36 | }) |
| 37 | |
| 38 | export const PostsResponseSchema = z.object({ |
| 39 | posts: z.array(postSchema).describe('List of posts'), |
| 40 | cursor: KeysetPaginationSchema.describe('Pagination cursor information'), |
| 41 | }) |
| 42 | |
| 43 | export class PostVo extends createZodDto(postSchema) {} |
| 44 | export class PostsResponseVo extends createZodDto(PostsResponseSchema) {} |
| 45 |