diff options
author | Chocobozzz <me@florianbigard.com> | 2018-09-11 16:27:07 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-09-13 14:05:49 +0200 |
commit | c48e82b5e0478434de30626d14594a97f2402e7c (patch) | |
tree | a78e5272bd0fe4f5b41831e571e02d05f1515b82 /server/models/video/video-file.ts | |
parent | a651038487faa838bda3ce04695b08bc65baff70 (diff) | |
download | PeerTube-c48e82b5e0478434de30626d14594a97f2402e7c.tar.gz PeerTube-c48e82b5e0478434de30626d14594a97f2402e7c.tar.zst PeerTube-c48e82b5e0478434de30626d14594a97f2402e7c.zip |
Basic video redundancy implementation
Diffstat (limited to 'server/models/video/video-file.ts')
-rw-r--r-- | server/models/video/video-file.ts | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/server/models/video/video-file.ts b/server/models/video/video-file.ts index 3bc4855f3..0907ea569 100644 --- a/server/models/video/video-file.ts +++ b/server/models/video/video-file.ts | |||
@@ -1,5 +1,18 @@ | |||
1 | import { values } from 'lodash' | 1 | import { values } from 'lodash' |
2 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' | 2 | import { |
3 | AllowNull, | ||
4 | BelongsTo, | ||
5 | Column, | ||
6 | CreatedAt, | ||
7 | DataType, | ||
8 | Default, | ||
9 | ForeignKey, | ||
10 | HasMany, | ||
11 | Is, | ||
12 | Model, | ||
13 | Table, | ||
14 | UpdatedAt | ||
15 | } from 'sequelize-typescript' | ||
3 | import { | 16 | import { |
4 | isVideoFileInfoHashValid, | 17 | isVideoFileInfoHashValid, |
5 | isVideoFileResolutionValid, | 18 | isVideoFileResolutionValid, |
@@ -10,6 +23,7 @@ import { CONSTRAINTS_FIELDS } from '../../initializers' | |||
10 | import { throwIfNotValid } from '../utils' | 23 | import { throwIfNotValid } from '../utils' |
11 | import { VideoModel } from './video' | 24 | import { VideoModel } from './video' |
12 | import * as Sequelize from 'sequelize' | 25 | import * as Sequelize from 'sequelize' |
26 | import { VideoRedundancyModel } from '../redundancy/video-redundancy' | ||
13 | 27 | ||
14 | @Table({ | 28 | @Table({ |
15 | tableName: 'videoFile', | 29 | tableName: 'videoFile', |
@@ -70,6 +84,15 @@ export class VideoFileModel extends Model<VideoFileModel> { | |||
70 | }) | 84 | }) |
71 | Video: VideoModel | 85 | Video: VideoModel |
72 | 86 | ||
87 | @HasMany(() => VideoRedundancyModel, { | ||
88 | foreignKey: { | ||
89 | allowNull: false | ||
90 | }, | ||
91 | onDelete: 'CASCADE', | ||
92 | hooks: true | ||
93 | }) | ||
94 | RedundancyVideos: VideoRedundancyModel[] | ||
95 | |||
73 | static isInfohashExists (infoHash: string) { | 96 | static isInfohashExists (infoHash: string) { |
74 | const query = 'SELECT 1 FROM "videoFile" WHERE "infoHash" = $infoHash LIMIT 1' | 97 | const query = 'SELECT 1 FROM "videoFile" WHERE "infoHash" = $infoHash LIMIT 1' |
75 | const options = { | 98 | const options = { |