]>
Commit | Line | Data |
---|---|---|
93e1258c | 1 | import { values } from 'lodash' |
3fd3ab2d | 2 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' |
d4f1e94c | 3 | import { isVideoFileInfoHashValid, isVideoFileResolutionValid, isVideoFileSizeValid } from '../../helpers/custom-validators/videos' |
3fd3ab2d C |
4 | import { CONSTRAINTS_FIELDS } from '../../initializers' |
5 | import { throwIfNotValid } from '../utils' | |
6 | import { VideoModel } from './video' | |
93e1258c | 7 | |
3fd3ab2d C |
8 | @Table({ |
9 | tableName: 'videoFile', | |
10 | indexes: [ | |
93e1258c | 11 | { |
3fd3ab2d | 12 | fields: [ 'videoId' ] |
93e1258c C |
13 | }, |
14 | { | |
3fd3ab2d | 15 | fields: [ 'infoHash' ] |
93e1258c | 16 | } |
93e1258c | 17 | ] |
3fd3ab2d C |
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, { | |
93e1258c | 50 | foreignKey: { |
93e1258c C |
51 | allowNull: false |
52 | }, | |
53 | onDelete: 'CASCADE' | |
54 | }) | |
3fd3ab2d | 55 | Video: VideoModel |
93e1258c | 56 | } |