返回 AiToEarn
media.schema.ts
根目录 / project / aitoearn-backend / libs / mongodb / src / schemas / media.schema.ts
1 /*
2 * @Author: nevin
3 * @Date: 2024-09-02 14:45:57
4 * @LastEditTime: 2025-02-22 12:37:22
5 * @LastEditors: nevin
6 * @Description: 媒体 Media media
7 */
8 import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
9 import { UserType } from '@yikart/common'
10 import { DEFAULT_SCHEMA_OPTIONS } from '../mongodb.constants'
11 import { WithTimestampSchema } from './timestamp.schema'
12
13 export enum MediaType {
14 VIDEO = 'video', // 视频
15 IMG = 'img', // 图片
16 }
17
18 export interface FileMetadata {
19 size?: number // bytes
20 mimeType: string
21 }
22
23 @Schema({ ...DEFAULT_SCHEMA_OPTIONS, collection: 'media' })
24 export class Media extends WithTimestampSchema {
25 id: string
26
27 @Prop({
28 required: true,
29 index: true,
30 })
31 userId: string
32
33 @Prop({
34 required: true,
35 index: true,
36 default: UserType.User,
37 })
38 userType: UserType
39
40 @Prop({
41 required: false,
42 index: true,
43 })
44 groupId?: string // 所属组ID
45
46 @Prop({
47 required: false,
48 index: true,
49 })
50 materialGroupId?: string // 所属组ID
51
52 @Prop({
53 required: true,
54 enum: MediaType,
55 index: true,
56 })
57 type: MediaType
58
59 @Prop({
60 required: true,
61 })
62 url: string
63
64 @Prop({
65 required: false,
66 })
67 thumbUrl?: string // 缩略图
68
69 @Prop({
70 required: false,
71 })
72 title?: string
73
74 @Prop({
75 required: false,
76 })
77 desc?: string
78
79 @Prop({
80 required: true,
81 default: 0,
82 })
83 useCount: number
84
85 @Prop({
86 type: Object,
87 })
88 metadata?: FileMetadata
89 }
90
91 export const MediaSchema = SchemaFactory.createForClass(Media)
92
92 lines TYPESCRIPT