]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/models/video/video-file.ts
Fix travis tests
[github/Chocobozzz/PeerTube.git] / server / models / video / video-file.ts
CommitLineData
93e1258c 1import { values } from 'lodash'
3a6f351b
C
2import { AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript'
3import {
4 isVideoFileInfoHashValid,
5 isVideoFileResolutionValid,
6 isVideoFileSizeValid,
7 isVideoFPSResolutionValid
8} from '../../helpers/custom-validators/videos'
3fd3ab2d
C
9import { CONSTRAINTS_FIELDS } from '../../initializers'
10import { throwIfNotValid } from '../utils'
11import { VideoModel } from './video'
93e1258c 12
3fd3ab2d
C
13@Table({
14 tableName: 'videoFile',
15 indexes: [
93e1258c 16 {
3fd3ab2d 17 fields: [ 'videoId' ]
93e1258c
C
18 },
19 {
3fd3ab2d 20 fields: [ 'infoHash' ]
93e1258c 21 }
93e1258c 22 ]
3fd3ab2d
C
23})
24export class VideoFileModel extends Model<VideoFileModel> {
25 @CreatedAt
26 createdAt: Date
27
28 @UpdatedAt
29 updatedAt: Date
30
31 @AllowNull(false)
32 @Is('VideoFileResolution', value => throwIfNotValid(value, isVideoFileResolutionValid, 'resolution'))
33 @Column
34 resolution: number
35
36 @AllowNull(false)
37 @Is('VideoFileSize', value => throwIfNotValid(value, isVideoFileSizeValid, 'size'))
38 @Column(DataType.BIGINT)
39 size: number
40
41 @AllowNull(false)
42 @Column(DataType.ENUM(values(CONSTRAINTS_FIELDS.VIDEOS.EXTNAME)))
43 extname: string
44
45 @AllowNull(false)
46 @Is('VideoFileSize', value => throwIfNotValid(value, isVideoFileInfoHashValid, 'info hash'))
47 @Column
48 infoHash: string
49
3a6f351b
C
50 @AllowNull(true)
51 @Default(null)
52 @Is('VideoFileFPS', value => throwIfNotValid(value, isVideoFPSResolutionValid, 'fps'))
53 @Column
54 fps: number
55
3fd3ab2d
C
56 @ForeignKey(() => VideoModel)
57 @Column
58 videoId: number
59
60 @BelongsTo(() => VideoModel, {
93e1258c 61 foreignKey: {
93e1258c
C
62 allowNull: false
63 },
64 onDelete: 'CASCADE'
65 })
3fd3ab2d 66 Video: VideoModel
93e1258c 67}