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