1 import { values } from 'lodash'
15 } from 'sequelize-typescript'
17 isVideoFileExtnameValid,
18 isVideoFileInfoHashValid,
19 isVideoFileResolutionValid,
21 isVideoFPSResolutionValid
22 } from '../../helpers/custom-validators/videos'
23 import { CONSTRAINTS_FIELDS } from '../../initializers'
24 import { throwIfNotValid } from '../utils'
25 import { VideoModel } from './video'
26 import * as Sequelize from 'sequelize'
27 import { VideoRedundancyModel } from '../redundancy/video-redundancy'
30 tableName: 'videoFile',
36 fields: [ 'infoHash' ]
39 fields: [ 'videoId', 'resolution', 'fps' ],
44 export class VideoFileModel extends Model<VideoFileModel> {
52 @Is('VideoFileResolution', value => throwIfNotValid(value, isVideoFileResolutionValid, 'resolution'))
57 @Is('VideoFileSize', value => throwIfNotValid(value, isVideoFileSizeValid, 'size'))
58 @Column(DataType.BIGINT)
62 @Is('VideoFileExtname', value => throwIfNotValid(value, isVideoFileExtnameValid, 'extname'))
67 @Is('VideoFileSize', value => throwIfNotValid(value, isVideoFileInfoHashValid, 'info hash'))
73 @Is('VideoFileFPS', value => throwIfNotValid(value, isVideoFPSResolutionValid, 'fps'))
77 @ForeignKey(() => VideoModel)
81 @BelongsTo(() => VideoModel, {
89 @HasMany(() => VideoRedundancyModel, {
96 RedundancyVideos: VideoRedundancyModel[]
98 static isInfohashExists (infoHash: string) {
99 const query = 'SELECT 1 FROM "videoFile" WHERE "infoHash" = $infoHash LIMIT 1'
101 type: Sequelize.QueryTypes.SELECT,
106 return VideoModel.sequelize.query(query, options)
108 return results.length === 1
112 static loadWithVideo (id: number) {
116 model: VideoModel.unscoped(),
122 return VideoFileModel.findById(id, options)
125 hasSameUniqueKeysThan (other: VideoFileModel) {
126 return this.fps === other.fps &&
127 this.resolution === other.resolution &&
128 this.videoId === other.videoId