返回 AiToEarn
material.schema.ts
根目录 / project / aitoearn-backend / libs / mongodb / src / schemas / material.schema.ts
1 import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
2 import { AccountType, UserType } from '@yikart/common'
3 import { DEFAULT_SCHEMA_OPTIONS } from '../mongodb.constants'
4 import { FileMetadata, MediaType } from './media.schema'
5 import { WithTimestampSchema } from './timestamp.schema'
6
7 export enum MaterialType {
8 VIDEO = 'video', // 视频
9 ARTICLE = 'article', // 文章
10 }
11
12 export enum MaterialStatus {
13 WAIT = 0,
14 SUCCESS = 1,
15 FAIL = -1,
16 }
17
18 /** 素材来源 */
19 export enum MaterialSource {
20 UPLOAD = 'upload',
21 PlaceDraft = 'place_draft',
22 }
23
24 @Schema({
25 versionKey: false,
26 toJSON: { virtuals: true },
27 toObject: { virtuals: true },
28 })
29 export class MaterialMedia {
30 @Prop({
31 required: true,
32 })
33 url: string
34
35 @Prop({
36 required: false,
37 })
38 thumbUrl?: string // 缩略图
39
40 @Prop({
41 type: Object,
42 })
43 metadata?: FileMetadata
44
45 @Prop({
46 required: true,
47 })
48 type: MediaType
49
50 @Prop({
51 required: false,
52 default: '',
53 })
54 content?: string
55
56 @Prop({
57 required: false,
58 })
59 mediaId?: string
60 }
61 @Schema({ ...DEFAULT_SCHEMA_OPTIONS, collection: 'material' })
62 export class Material extends WithTimestampSchema {
63 id: string
64
65 @Prop({
66 required: true,
67 index: true,
68 })
69 userId: string
70
71 @Prop({
72 required: true,
73 index: true,
74 default: UserType.User,
75 })
76 userType: UserType
77
78 @Prop({
79 required: true,
80 index: true,
81 })
82 groupId: string // 所属组ID
83
84 @Prop({
85 required: false,
86 index: true,
87 })
88 taskId?: string // 使用生成的任务ID
89
90 /** 素材来源 */
91 @Prop({
92 required: true,
93 enum: MaterialSource,
94 default: MaterialSource.UPLOAD,
95 index: true,
96 })
97 source: MaterialSource
98
99 @Prop({
100 required: true,
101 enum: MaterialType,
102 index: true,
103 })
104 type: MaterialType
105
106 @Prop({
107 required: false,
108 })
109 coverUrl?: string
110
111 @Prop({
112 required: true,
113 type: [MaterialMedia],
114 default: [],
115 })
116 mediaList: MaterialMedia[]
117
118 @Prop({
119 required: false,
120 })
121 title?: string
122
123 @Prop({
124 required: false,
125 })
126 desc?: string
127
128 // 话题
129 @Prop({
130 required: true,
131 type: [String],
132 default: [],
133 })
134 topics: string[]
135
136 @Prop({
137 required: false,
138 default: {},
139 type: Object, // 明确指定类型为 Object
140 })
141 option?: Record<string, any>
142
143 @Prop({
144 required: true,
145 enum: MaterialStatus,
146 default: MaterialStatus.SUCCESS,
147 })
148 status: MaterialStatus
149
150 @Prop({
151 required: false,
152 default: '',
153 })
154 message?: string
155
156 @Prop({
157 required: true,
158 default: 0,
159 index: true,
160 })
161 useCount: number
162
163 @Prop({
164 required: false,
165 index: true,
166 })
167 maxUseCount?: number
168
169 // 是否自动删除素材
170 @Prop({
171 required: true,
172 default: false,
173 })
174 autoDeleteMedia: boolean
175
176 // 模型
177 @Prop({
178 required: false,
179 })
180 model?: string
181
182 // AI 生成参数(如 prompt、aspectRatio、duration、imageUrls 等,仅 AI 生成草稿有值)
183 @Prop({
184 required: false,
185 default: undefined,
186 type: Object,
187 })
188 generationParams?: Record<string, any>
189
190 // 适用的频道类型
191 @Prop({
192 required: true,
193 type: [String],
194 enum: AccountType,
195 default: [],
196 index: true,
197 })
198 accountTypes: AccountType[]
199 }
200
201 export const MaterialSchema = SchemaFactory.createForClass(Material)
202
202 lines TYPESCRIPT