1 import { values } from 'lodash'
2 import * as Sequelize from 'sequelize'
3 import { isVideoFileInfoHashValid, isVideoFileResolutionValid, isVideoFileSizeValid } from '../../helpers/custom-validators/videos'
4 import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
6 import { addMethodsToModel } from '../utils'
7 import { VideoFileAttributes, VideoFileInstance } from './video-file-interface'
9 let VideoFile: Sequelize.Model<VideoFileInstance, VideoFileAttributes>
11 export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
12 VideoFile = sequelize.define<VideoFileInstance, VideoFileAttributes>('VideoFile',
15 type: DataTypes.INTEGER,
18 resolutionValid: value => {
19 const res = isVideoFileResolutionValid(value)
20 if (res === false) throw new Error('Video file resolution is not valid.')
25 type: DataTypes.BIGINT,
29 const res = isVideoFileSizeValid(value)
30 if (res === false) throw new Error('Video file size is not valid.')
35 type: DataTypes.ENUM(values(CONSTRAINTS_FIELDS.VIDEOS.EXTNAME)),
39 type: DataTypes.STRING,
42 infoHashValid: value => {
43 const res = isVideoFileInfoHashValid(value)
44 if (res === false) throw new Error('Video file info hash is not valid.')
55 fields: [ 'infoHash' ]
61 const classMethods = [
64 addMethodsToModel(VideoFile, classMethods)
69 // ------------------------------ STATICS ------------------------------
71 function associate (models) {
72 VideoFile.belongsTo(models.Video, {
81 // ------------------------------ METHODS ------------------------------