| 1 | /* |
| 2 | * @Author: nevin |
| 3 | * @Date: 2021-12-24 13:46:31 |
| 4 | * @LastEditors: nevin |
| 5 | * @LastEditTime: 2024-08-30 15:01:32 |
| 6 | * @Description: 发布记录 |
| 7 | */ |
| 8 | import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose' |
| 9 | import { AccountType, WorkStatus } from '@yikart/common' |
| 10 | import mongoose from 'mongoose' |
| 11 | import { PublishRecordLinkStatus, PublishRecordSource, PublishStatus, PublishType } from '../enums' |
| 12 | import { DEFAULT_SCHEMA_OPTIONS } from '../mongodb.constants' |
| 13 | import { PublishErrorData } from './publishing-task-meta.schema' |
| 14 | import { WithTimestampSchema } from './timestamp.schema' |
| 15 | |
| 16 | @Schema({ ...DEFAULT_SCHEMA_OPTIONS, collection: 'publishRecord' }) |
| 17 | export class PublishRecord extends WithTimestampSchema { |
| 18 | id: string |
| 19 | |
| 20 | @Prop({ |
| 21 | required: false, |
| 22 | type: String, |
| 23 | default: '', |
| 24 | }) |
| 25 | userId: string |
| 26 | |
| 27 | @Prop({ |
| 28 | required: false, |
| 29 | }) |
| 30 | flowId?: string // 前端传入的流水ID |
| 31 | |
| 32 | @Prop({ |
| 33 | required: false, |
| 34 | type: String, |
| 35 | }) |
| 36 | taskId?: string // 任务ID |
| 37 | |
| 38 | @Prop({ |
| 39 | required: false, |
| 40 | type: String, |
| 41 | index: true, |
| 42 | }) |
| 43 | materialGroupId?: string // 草稿箱ID |
| 44 | |
| 45 | @Prop({ |
| 46 | required: false, |
| 47 | type: String, |
| 48 | index: true, |
| 49 | }) |
| 50 | materialId?: string // 草稿ID |
| 51 | |
| 52 | @Prop({ |
| 53 | required: true, |
| 54 | enum: PublishType, |
| 55 | }) |
| 56 | type: PublishType |
| 57 | |
| 58 | @Prop({ |
| 59 | required: false, |
| 60 | }) |
| 61 | title?: string |
| 62 | |
| 63 | @Prop({ |
| 64 | required: false, |
| 65 | }) |
| 66 | desc?: string // 主要内容 |
| 67 | |
| 68 | @Prop({ |
| 69 | required: false, |
| 70 | }) |
| 71 | accountId?: string |
| 72 | |
| 73 | // 话题 |
| 74 | @Prop({ |
| 75 | required: false, |
| 76 | type: [String], |
| 77 | default: [], |
| 78 | }) |
| 79 | topics: string[] |
| 80 | |
| 81 | @Prop({ |
| 82 | required: true, |
| 83 | }) |
| 84 | accountType: AccountType |
| 85 | |
| 86 | @Prop({ |
| 87 | required: false, |
| 88 | }) |
| 89 | uid?: string |
| 90 | |
| 91 | @Prop({ |
| 92 | required: false, |
| 93 | }) |
| 94 | videoUrl?: string |
| 95 | |
| 96 | @Prop({ |
| 97 | required: false, |
| 98 | }) |
| 99 | coverUrl?: string |
| 100 | |
| 101 | // 图片列表 |
| 102 | @Prop({ |
| 103 | required: false, |
| 104 | type: [String], |
| 105 | }) |
| 106 | imgUrlList?: string[] |
| 107 | |
| 108 | @Prop({ |
| 109 | required: true, |
| 110 | type: Date, |
| 111 | }) |
| 112 | publishTime: Date |
| 113 | |
| 114 | @Prop({ |
| 115 | required: true, |
| 116 | enum: PublishStatus, |
| 117 | default: PublishStatus.WaitingForPublish, |
| 118 | }) |
| 119 | status: PublishStatus |
| 120 | |
| 121 | @Prop({ |
| 122 | required: false, |
| 123 | }) |
| 124 | queueId?: string |
| 125 | |
| 126 | @Prop({ |
| 127 | required: true, |
| 128 | default: false, |
| 129 | }) |
| 130 | inQueue: boolean |
| 131 | |
| 132 | @Prop({ |
| 133 | required: false, |
| 134 | default: false, |
| 135 | }) |
| 136 | queued: boolean |
| 137 | |
| 138 | @Prop({ |
| 139 | required: false, |
| 140 | type: PublishErrorData, |
| 141 | }) |
| 142 | errorData?: PublishErrorData |
| 143 | |
| 144 | @Prop({ |
| 145 | required: false, |
| 146 | }) |
| 147 | errorMsg?: string |
| 148 | |
| 149 | @Prop({ |
| 150 | required: false, |
| 151 | type: mongoose.Schema.Types.Mixed, |
| 152 | }) |
| 153 | option?: any |
| 154 | |
| 155 | @Prop({ |
| 156 | required: false, |
| 157 | index: false, |
| 158 | type: String, |
| 159 | default: '', |
| 160 | }) |
| 161 | dataId?: string |
| 162 | |
| 163 | @Prop({ |
| 164 | required: false, |
| 165 | index: true, |
| 166 | type: String, |
| 167 | }) |
| 168 | uniqueId?: string // 作品唯一标识 (accountType + dataId) |
| 169 | |
| 170 | @Prop({ |
| 171 | required: false, |
| 172 | type: String, |
| 173 | }) |
| 174 | workLink?: string |
| 175 | |
| 176 | @Prop({ |
| 177 | required: false, |
| 178 | type: String, |
| 179 | }) |
| 180 | originalWorkLink?: string |
| 181 | |
| 182 | @Prop({ |
| 183 | required: false, |
| 184 | type: String, |
| 185 | enum: WorkStatus, |
| 186 | }) |
| 187 | workStatus?: WorkStatus |
| 188 | |
| 189 | @Prop({ |
| 190 | required: false, |
| 191 | type: String, |
| 192 | }) |
| 193 | platformWorkId?: string |
| 194 | |
| 195 | @Prop({ |
| 196 | required: false, |
| 197 | type: String, |
| 198 | enum: PublishRecordLinkStatus, |
| 199 | }) |
| 200 | linkStatus?: PublishRecordLinkStatus |
| 201 | |
| 202 | @Prop({ |
| 203 | required: false, |
| 204 | type: String, |
| 205 | }) |
| 206 | linkError?: string |
| 207 | |
| 208 | @Prop({ |
| 209 | required: false, |
| 210 | type: mongoose.Schema.Types.Mixed, |
| 211 | }) |
| 212 | linkMeta?: Record<string, any> |
| 213 | |
| 214 | @Prop({ |
| 215 | required: false, |
| 216 | type: mongoose.Schema.Types.Mixed, |
| 217 | }) |
| 218 | dataOption?: Record<string, any> |
| 219 | |
| 220 | @Prop({ |
| 221 | required: false, |
| 222 | type: mongoose.Schema.Types.Mixed, |
| 223 | }) |
| 224 | pendingMediaJobs?: Record<string, any>[] |
| 225 | |
| 226 | @Prop({ |
| 227 | required: false, |
| 228 | type: mongoose.Schema.Types.Mixed, |
| 229 | }) |
| 230 | pendingUpdate?: Record<string, any> |
| 231 | |
| 232 | @Prop({ |
| 233 | required: false, |
| 234 | type: String, |
| 235 | enum: PublishRecordSource, |
| 236 | }) |
| 237 | source?: PublishRecordSource |
| 238 | } |
| 239 | |
| 240 | export const PublishRecordSchema = SchemaFactory.createForClass(PublishRecord) |
| 241 | |
| 242 | PublishRecordSchema.index({ status: 1, publishTime: 1 }) |
| 243 | PublishRecordSchema.index( |
| 244 | { userId: 1, flowId: 1, accountId: 1, accountType: 1 }, |
| 245 | { |
| 246 | unique: true, |
| 247 | name: 'userId_1_flowId_1_accountId_1_accountType_1', |
| 248 | partialFilterExpression: { |
| 249 | userId: { $type: 'string', $ne: '' }, |
| 250 | flowId: { $type: 'string', $ne: '' }, |
| 251 | accountId: { $type: 'string', $ne: '' }, |
| 252 | }, |
| 253 | }, |
| 254 | ) |
| 255 |