1 import { values } from 'lodash'
2 import { AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript'
4 isVideoFileInfoHashValid,
5 isVideoFileResolutionValid,
7 isVideoFPSResolutionValid
8 } from '../../helpers/custom-validators/videos'
9 import { CONSTRAINTS_FIELDS } from '../../initializers'
10 import { throwIfNotValid } from '../utils'
11 import { VideoModel } from './video'
12 import * as Sequelize from 'sequelize'
15 tableName: 'videoFile',
21 fields: [ 'infoHash' ]
24 fields: [ 'videoId', 'resolution', 'fps' ],
29 export class VideoFileModel extends Model<VideoFileModel> {
37 @Is('VideoFileResolution', value => throwIfNotValid(value, isVideoFileResolutionValid, 'resolution'))
42 @Is('VideoFileSize', value => throwIfNotValid(value, isVideoFileSizeValid, 'size'))
43 @Column(DataType.BIGINT)
47 @Column(DataType.ENUM(values(CONSTRAINTS_FIELDS.VIDEOS.EXTNAME)))
51 @Is('VideoFileSize', value => throwIfNotValid(value, isVideoFileInfoHashValid, 'info hash'))
57 @Is('VideoFileFPS', value => throwIfNotValid(value, isVideoFPSResolutionValid, 'fps'))
61 @ForeignKey(() => VideoModel)
65 @BelongsTo(() => VideoModel, {
73 static isInfohashExists (infoHash: string) {
74 const query = 'SELECT 1 FROM "videoFile" WHERE "infoHash" = $infoHash LIMIT 1'
76 type: Sequelize.QueryTypes.SELECT,
81 return VideoModel.sequelize.query(query, options)
83 return results.length === 1