aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video-file.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-09-11 16:27:07 +0200
committerChocobozzz <me@florianbigard.com>2018-09-13 14:05:49 +0200
commitc48e82b5e0478434de30626d14594a97f2402e7c (patch)
treea78e5272bd0fe4f5b41831e571e02d05f1515b82 /server/models/video/video-file.ts
parenta651038487faa838bda3ce04695b08bc65baff70 (diff)
downloadPeerTube-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.ts25
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 @@
1import { values } from 'lodash' 1import { values } from 'lodash'
2import { AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' 2import {
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'
3import { 16import {
4 isVideoFileInfoHashValid, 17 isVideoFileInfoHashValid,
5 isVideoFileResolutionValid, 18 isVideoFileResolutionValid,
@@ -10,6 +23,7 @@ import { CONSTRAINTS_FIELDS } from '../../initializers'
10import { throwIfNotValid } from '../utils' 23import { throwIfNotValid } from '../utils'
11import { VideoModel } from './video' 24import { VideoModel } from './video'
12import * as Sequelize from 'sequelize' 25import * as Sequelize from 'sequelize'
26import { 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 = {