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