+ if (options.categoryOneOf) {
+ query.where['category'] = {
+ [Sequelize.Op.or]: options.categoryOneOf
+ }
+ }
+
+ if (options.licenceOneOf) {
+ query.where['licence'] = {
+ [Sequelize.Op.or]: options.licenceOneOf
+ }
+ }
+
+ if (options.languageOneOf) {
+ query.where['language'] = {
+ [Sequelize.Op.or]: options.languageOneOf
+ }
+ }
+
+ if (options.accountId) {
+ accountInclude.where = {
+ id: options.accountId
+ }
+ }
+
+ if (options.videoChannelId) {
+ videoChannelInclude.where = {
+ id: options.videoChannelId
+ }
+ }
+
+ return query
+ },
+ [ScopeNames.WITH_ACCOUNT_DETAILS]: {
+ include: [
+ {
+ model: () => VideoChannelModel.unscoped(),
+ required: true,
+ include: [
+ {
+ attributes: {
+ exclude: [ 'privateKey', 'publicKey' ]
+ },
+ model: () => ActorModel.unscoped(),
+ required: true,
+ include: [
+ {
+ attributes: [ 'host' ],
+ model: () => ServerModel.unscoped(),
+ required: false
+ },
+ {
+ model: () => AvatarModel.unscoped(),
+ required: false
+ }
+ ]
+ },
+ {
+ model: () => AccountModel.unscoped(),
+ required: true,
+ include: [
+ {
+ model: () => ActorModel.unscoped(),
+ attributes: {
+ exclude: [ 'privateKey', 'publicKey' ]
+ },
+ required: true,
+ include: [
+ {
+ attributes: [ 'host' ],
+ model: () => ServerModel.unscoped(),
+ required: false
+ },
+ {
+ model: () => AvatarModel.unscoped(),
+ required: false
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ [ScopeNames.WITH_TAGS]: {
+ include: [ () => TagModel ]
+ },
+ [ScopeNames.WITH_FILES]: {
+ include: [
+ {
+ model: () => VideoFileModel.unscoped(),
+ required: true
+ }
+ ]
+ },
+ [ScopeNames.WITH_SCHEDULED_UPDATE]: {
+ include: [
+ {
+ model: () => ScheduleVideoUpdateModel.unscoped(),
+ required: false
+ }
+ ]
+ }
+})
+@Table({
+ tableName: 'video',
+ indexes
+})
+export class VideoModel extends Model<VideoModel> {
+
+ @AllowNull(false)
+ @Default(DataType.UUIDV4)
+ @IsUUID(4)
+ @Column(DataType.UUID)
+ uuid: string
+
+ @AllowNull(false)
+ @Is('VideoName', value => throwIfNotValid(value, isVideoNameValid, 'name'))
+ @Column
+ name: string
+
+ @AllowNull(true)
+ @Default(null)
+ @Is('VideoCategory', value => throwIfNotValid(value, isVideoCategoryValid, 'category'))
+ @Column
+ category: number
+
+ @AllowNull(true)
+ @Default(null)
+ @Is('VideoLicence', value => throwIfNotValid(value, isVideoLicenceValid, 'licence'))
+ @Column
+ licence: number
+
+ @AllowNull(true)
+ @Default(null)
+ @Is('VideoLanguage', value => throwIfNotValid(value, isVideoLanguageValid, 'language'))
+ @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEOS.LANGUAGE.max))
+ language: string
+
+ @AllowNull(false)
+ @Is('VideoPrivacy', value => throwIfNotValid(value, isVideoPrivacyValid, 'privacy'))
+ @Column
+ privacy: number
+
+ @AllowNull(false)
+ @Is('VideoNSFW', value => throwIfNotValid(value, isBooleanValid, 'NSFW boolean'))
+ @Column
+ nsfw: boolean
+
+ @AllowNull(true)
+ @Default(null)
+ @Is('VideoDescription', value => throwIfNotValid(value, isVideoDescriptionValid, 'description'))
+ @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEOS.DESCRIPTION.max))
+ description: string
+
+ @AllowNull(true)
+ @Default(null)
+ @Is('VideoSupport', value => throwIfNotValid(value, isVideoSupportValid, 'support'))
+ @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEOS.SUPPORT.max))
+ support: string
+
+ @AllowNull(false)
+ @Is('VideoDuration', value => throwIfNotValid(value, isVideoDurationValid, 'duration'))
+ @Column
+ duration: number
+
+ @AllowNull(false)
+ @Default(0)
+ @IsInt
+ @Min(0)
+ @Column
+ views: number
+
+ @AllowNull(false)
+ @Default(0)
+ @IsInt
+ @Min(0)
+ @Column
+ likes: number
+
+ @AllowNull(false)
+ @Default(0)
+ @IsInt
+ @Min(0)
+ @Column
+ dislikes: number
+
+ @AllowNull(false)
+ @Column
+ remote: boolean
+
+ @AllowNull(false)
+ @Is('VideoUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'url'))
+ @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEOS.URL.max))
+ url: string
+
+ @AllowNull(false)
+ @Column
+ commentsEnabled: boolean
+
+ @AllowNull(false)
+ @Column
+ waitTranscoding: boolean
+
+ @AllowNull(false)
+ @Default(null)
+ @Is('VideoState', value => throwIfNotValid(value, isVideoStateValid, 'state'))
+ @Column
+ state: VideoState
+
+ @CreatedAt
+ createdAt: Date
+
+ @UpdatedAt
+ updatedAt: Date
+
+ @AllowNull(false)
+ @Default(Sequelize.NOW)
+ @Column
+ publishedAt: Date
+
+ @ForeignKey(() => VideoChannelModel)
+ @Column
+ channelId: number
+
+ @BelongsTo(() => VideoChannelModel, {
+ foreignKey: {
+ allowNull: true
+ },
+ hooks: true
+ })
+ VideoChannel: VideoChannelModel
+
+ @BelongsToMany(() => TagModel, {
+ foreignKey: 'videoId',
+ through: () => VideoTagModel,
+ onDelete: 'CASCADE'
+ })
+ Tags: TagModel[]
+
+ @HasMany(() => VideoAbuseModel, {