1 import * as Sequelize from 'sequelize'
2 import { values } from 'lodash'
4 import { CONSTRAINTS_FIELDS } from '../../initializers'
6 isVideoFileResolutionValid,
8 isVideoFileInfoHashValid
11 import { addMethodsToModel } from '../utils'
15 } from './video-file-interface'
17 let VideoFile: Sequelize.Model<VideoFileInstance, VideoFileAttributes>
19 export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
20 VideoFile = sequelize.define<VideoFileInstance, VideoFileAttributes>('VideoFile',
23 type: DataTypes.INTEGER,
26 resolutionValid: value => {
27 const res = isVideoFileResolutionValid(value)
28 if (res === false) throw new Error('Video file resolution is not valid.')
33 type: DataTypes.BIGINT,
37 const res = isVideoFileSizeValid(value)
38 if (res === false) throw new Error('Video file size is not valid.')
43 type: DataTypes.ENUM(values(CONSTRAINTS_FIELDS.VIDEOS.EXTNAME)),
47 type: DataTypes.STRING,
50 infoHashValid: value => {
51 const res = isVideoFileInfoHashValid(value)
52 if (res === false) throw new Error('Video file info hash is not valid.')
63 fields: [ 'infoHash' ]
69 const classMethods = [
72 addMethodsToModel(VideoFile, classMethods)
77 // ------------------------------ STATICS ------------------------------
79 function associate (models) {
80 VideoFile.belongsTo(models.Video, {
89 // ------------------------------ METHODS ------------------------------