| 1 | import { AccountType, createZodDto, FileUtil, TableDto } from '@yikart/common' |
| 2 | import { MaterialStatus, MaterialType, MediaType } from '@yikart/mongodb' |
| 3 | import { z } from 'zod' |
| 4 | |
| 5 | const MaterialIdSchema = z.object({ |
| 6 | id: z.string().describe('草稿ID'), |
| 7 | }) |
| 8 | export class MaterialIdDto extends createZodDto(MaterialIdSchema) { } |
| 9 | |
| 10 | export const MaterialMediaSchema = z.object({ |
| 11 | id: z.string().optional().describe('资源ID'), |
| 12 | url: FileUtil.zodTrimHost(), |
| 13 | type: z.enum(MediaType).describe('资源类型'), |
| 14 | thumbUrl: FileUtil.zodTrimHost().optional().describe('缩略图'), |
| 15 | content: z.string().optional().describe('文本内容'), |
| 16 | mediaId: z.string().optional().describe('资源ID'), |
| 17 | }) |
| 18 | |
| 19 | export const CreateMaterialSchema = z.object({ |
| 20 | groupId: z.string().describe('分组ID'), |
| 21 | coverUrl: FileUtil.zodTrimHost().optional().describe('封面图'), |
| 22 | mediaList: z.array(MaterialMediaSchema).describe('资源列表'), |
| 23 | title: z.string().describe('标题'), |
| 24 | desc: z.string().optional().describe('描述'), |
| 25 | topics: z.array(z.string()).optional().default([]).describe('话题'), |
| 26 | option: z.any().optional().describe('其他属性'), |
| 27 | autoDeleteMedia: z.boolean().optional().describe('自动删除草稿'), |
| 28 | type: z.enum(MaterialType).describe('草稿类型'), |
| 29 | maxUseCount: z.number().int().positive().optional().describe('最大使用次数'), |
| 30 | accountTypes: z.array(z.enum(AccountType)).optional().default([]).describe('适用的频道类型'), |
| 31 | }) |
| 32 | export class CreateMaterialDto extends createZodDto(CreateMaterialSchema) { } |
| 33 | |
| 34 | export const UpdateMaterialSchema = z.object({ |
| 35 | coverUrl: FileUtil.zodTrimHost().optional().describe('封面图'), |
| 36 | mediaList: z.array(MaterialMediaSchema).describe('资源列表'), |
| 37 | title: z.string().describe('标题'), |
| 38 | desc: z.string().optional().describe('描述'), |
| 39 | topics: z.array(z.string()).optional().describe('话题'), |
| 40 | option: z.any().optional().describe('其他属性'), |
| 41 | autoDeleteMedia: z.boolean().optional().describe('自动删除草稿'), |
| 42 | maxUseCount: z.number().int().positive().optional().describe('最大使用次数'), |
| 43 | accountTypes: z.array(z.enum(AccountType)).optional().describe('适用的频道类型'), |
| 44 | }) |
| 45 | export class UpdateMaterialDto extends createZodDto(UpdateMaterialSchema) { } |
| 46 | |
| 47 | export const MaterialFilterSchema = z.object({ |
| 48 | title: z.string({ message: '标题' }).optional(), |
| 49 | groupId: z.string({ message: '组ID' }).optional(), |
| 50 | status: z.enum(MaterialStatus, { message: '草稿状态' }).optional(), |
| 51 | type: z.enum(MaterialType, { message: '草稿类型' }).optional(), |
| 52 | useCount: z.coerce.number().optional().describe('最小使用次数'), |
| 53 | }) |
| 54 | |
| 55 | export class MaterialFilterDto extends createZodDto(MaterialFilterSchema) { } |
| 56 | |
| 57 | const MaterialListSchema = z.object({ |
| 58 | filter: MaterialFilterSchema, |
| 59 | page: TableDto.schema, |
| 60 | }) |
| 61 | |
| 62 | export class MaterialListDto extends createZodDto(MaterialListSchema) { } |
| 63 | |
| 64 | const MediaIdsSchema = z.object({ |
| 65 | ids: z.array(z.string()).min(1).describe('ID列表'), |
| 66 | }) |
| 67 | export class MaterialIdsDto extends createZodDto(MediaIdsSchema) { } |
| 68 | |
| 69 | const DeleteByUseCountSchema = z.object({ |
| 70 | groupId: z.string().describe('草稿箱ID'), |
| 71 | minUseCount: z.number().int().min(0).describe('最小使用次数(大于等于该值的草稿将被删除)'), |
| 72 | }) |
| 73 | export class DeleteByUseCountDto extends createZodDto(DeleteByUseCountSchema, 'DeleteByUseCountDto') {} |
| 74 | |
| 75 | const TransferMaterialSchema = z.object({ |
| 76 | ids: z.array(z.string()).min(1).describe('草稿ID列表'), |
| 77 | targetGroupId: z.string().describe('目标草稿箱ID'), |
| 78 | mode: z.enum(['move', 'copy']).describe('转移模式:move 移动,copy 复制'), |
| 79 | }) |
| 80 | export class TransferMaterialDto extends createZodDto(TransferMaterialSchema, 'TransferMaterialDto') {} |
| 81 | |
| 82 | const GetOptimalMaterialSchema = z.object({ |
| 83 | groupId: z.string().describe('草稿箱ID'), |
| 84 | accountType: z.enum(AccountType).describe('平台类型'), |
| 85 | }) |
| 86 | export class GetOptimalMaterialDto extends createZodDto(GetOptimalMaterialSchema) { } |
| 87 |