]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/models/video/video-file.ts
Delete actor too when deleting account/video channel
[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' ]
8cd72bd3
C
21 },
22 {
23 fields: [ 'videoId', 'resolution', 'fps' ],
24 unique: true
93e1258c 25 }
93e1258c 26 ]
3fd3ab2d
C
27})
28export 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
3a6f351b
C
54 @AllowNull(true)
55 @Default(null)
56 @Is('VideoFileFPS', value => throwIfNotValid(value, isVideoFPSResolutionValid, 'fps'))
57 @Column
58 fps: number
59
3fd3ab2d
C
60 @ForeignKey(() => VideoModel)
61 @Column
62 videoId: number
63
64 @BelongsTo(() => VideoModel, {
93e1258c 65 foreignKey: {
93e1258c
C
66 allowNull: false
67 },
68 onDelete: 'CASCADE'
69 })
3fd3ab2d 70 Video: VideoModel
93e1258c 71}