| 1 | import { AccountType, createZodDto } from '@yikart/common' |
| 2 | import { z } from 'zod' |
| 3 | import { ChannelPaginationInputWithDefaultSchema } from '../platforms/platform-pagination.dto' |
| 4 | import { ChannelEngagementFunctionName } from '../platforms/platforms.interface' |
| 5 | |
| 6 | export const EngagementExecutionQuerySchema = z.object({ |
| 7 | accountId: z.string().min(1).describe('动作执行账号 ID'), |
| 8 | }) |
| 9 | |
| 10 | export class EngagementExecutionQueryDto extends createZodDto(EngagementExecutionQuerySchema) {} |
| 11 | |
| 12 | export const EngagementCommentsQuerySchema = EngagementExecutionQuerySchema.extend({ |
| 13 | platform: z.enum(AccountType).describe('平台'), |
| 14 | platformWorkId: z.string().min(1).describe('平台作品 ID'), |
| 15 | pagination: ChannelPaginationInputWithDefaultSchema.describe('分页参数'), |
| 16 | }) |
| 17 | |
| 18 | export class EngagementCommentsQueryDto extends createZodDto(EngagementCommentsQuerySchema) {} |
| 19 | |
| 20 | export const CreateEngagementCommentBodySchema = z.object({ |
| 21 | platform: z.enum(AccountType).describe('平台'), |
| 22 | platformWorkId: z.string().min(1).describe('平台作品 ID'), |
| 23 | content: z.string().min(1).describe('评论内容'), |
| 24 | parentCommentId: z.string().optional().describe('父评论 ID'), |
| 25 | }) |
| 26 | |
| 27 | export class CreateEngagementCommentBodyDto extends createZodDto(CreateEngagementCommentBodySchema) {} |
| 28 | |
| 29 | export const DeleteEngagementCommentFunctionDataSchema = z.object({ |
| 30 | commentId: z.string().min(1).describe('评论 ID'), |
| 31 | }) |
| 32 | |
| 33 | export const EngagementCommentFunctionDataSchema = z.object({ |
| 34 | commentId: z.string().min(1).describe('评论或回复 ID'), |
| 35 | }) |
| 36 | |
| 37 | export const EngagementWorkFunctionDataSchema = z.object({ |
| 38 | platformWorkId: z.string().min(1).describe('平台作品 ID'), |
| 39 | }) |
| 40 | |
| 41 | export const QuoteEngagementWorkFunctionDataSchema = EngagementWorkFunctionDataSchema.extend({ |
| 42 | content: z.string().min(1).describe('引用发布内容'), |
| 43 | }) |
| 44 | |
| 45 | export const EngagementAccountFunctionDataSchema = z.object({ |
| 46 | targetPlatformUid: z.string().min(1).describe('目标平台账号 UID'), |
| 47 | }) |
| 48 | |
| 49 | export const CallEngagementFunctionBodySchema = z.object({ |
| 50 | platform: z.enum(AccountType).describe('平台'), |
| 51 | name: z.enum(ChannelEngagementFunctionName).describe('互动函数名称'), |
| 52 | data: z.record(z.string(), z.unknown()).describe('函数参数'), |
| 53 | }) |
| 54 | |
| 55 | export class CallEngagementFunctionBodyDto extends createZodDto(CallEngagementFunctionBodySchema) {} |
| 56 | |
| 57 | export function getEngagementFunctionDataSchema(name: ChannelEngagementFunctionName): z.ZodTypeAny { |
| 58 | switch (name) { |
| 59 | case ChannelEngagementFunctionName.DeleteComment: |
| 60 | return DeleteEngagementCommentFunctionDataSchema |
| 61 | case ChannelEngagementFunctionName.HideReply: |
| 62 | case ChannelEngagementFunctionName.UnhideReply: |
| 63 | return EngagementCommentFunctionDataSchema |
| 64 | case ChannelEngagementFunctionName.Like: |
| 65 | case ChannelEngagementFunctionName.Unlike: |
| 66 | case ChannelEngagementFunctionName.Repost: |
| 67 | case ChannelEngagementFunctionName.UndoRepost: |
| 68 | case ChannelEngagementFunctionName.Bookmark: |
| 69 | case ChannelEngagementFunctionName.RemoveBookmark: |
| 70 | return EngagementWorkFunctionDataSchema |
| 71 | case ChannelEngagementFunctionName.Quote: |
| 72 | return QuoteEngagementWorkFunctionDataSchema |
| 73 | case ChannelEngagementFunctionName.Follow: |
| 74 | case ChannelEngagementFunctionName.Unfollow: |
| 75 | return EngagementAccountFunctionDataSchema |
| 76 | } |
| 77 | } |
| 78 |