aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video-live.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video/video-live.ts')
-rw-r--r--server/models/video/video-live.ts57
1 files changed, 54 insertions, 3 deletions
diff --git a/server/models/video/video-live.ts b/server/models/video/video-live.ts
index d2788ef4f..290e1dda7 100644
--- a/server/models/video/video-live.ts
+++ b/server/models/video/video-live.ts
@@ -1,11 +1,24 @@
1import { AllowNull, BelongsTo, Column, CreatedAt, DataType, DefaultScope, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript' 1import {
2 BeforeDestroy,
3 AllowNull,
4 BelongsTo,
5 Column,
6 CreatedAt,
7 DataType,
8 DefaultScope,
9 ForeignKey,
10 Model,
11 Table,
12 UpdatedAt
13} from 'sequelize-typescript'
2import { CONFIG } from '@server/initializers/config' 14import { CONFIG } from '@server/initializers/config'
3import { WEBSERVER } from '@server/initializers/constants' 15import { WEBSERVER } from '@server/initializers/constants'
4import { MVideoLive, MVideoLiveVideo } from '@server/types/models' 16import { MVideoLive, MVideoLiveVideoWithSetting } from '@server/types/models'
5import { LiveVideo, LiveVideoLatencyMode, VideoState } from '@shared/models' 17import { LiveVideo, LiveVideoLatencyMode, VideoState } from '@shared/models'
6import { AttributesOnly } from '@shared/typescript-utils' 18import { AttributesOnly } from '@shared/typescript-utils'
7import { VideoModel } from './video' 19import { VideoModel } from './video'
8import { VideoBlacklistModel } from './video-blacklist' 20import { VideoBlacklistModel } from './video-blacklist'
21import { VideoLiveReplaySettingModel } from './video-live-replay-setting'
9 22
10@DefaultScope(() => ({ 23@DefaultScope(() => ({
11 include: [ 24 include: [
@@ -18,6 +31,10 @@ import { VideoBlacklistModel } from './video-blacklist'
18 required: false 31 required: false
19 } 32 }
20 ] 33 ]
34 },
35 {
36 model: VideoLiveReplaySettingModel,
37 required: false
21 } 38 }
22 ] 39 ]
23})) 40}))
@@ -27,6 +44,10 @@ import { VideoBlacklistModel } from './video-blacklist'
27 { 44 {
28 fields: [ 'videoId' ], 45 fields: [ 'videoId' ],
29 unique: true 46 unique: true
47 },
48 {
49 fields: [ 'replaySettingId' ],
50 unique: true
30 } 51 }
31 ] 52 ]
32}) 53})
@@ -66,6 +87,27 @@ export class VideoLiveModel extends Model<Partial<AttributesOnly<VideoLiveModel>
66 }) 87 })
67 Video: VideoModel 88 Video: VideoModel
68 89
90 @ForeignKey(() => VideoLiveReplaySettingModel)
91 @Column
92 replaySettingId: number
93
94 @BelongsTo(() => VideoLiveReplaySettingModel, {
95 foreignKey: {
96 allowNull: true
97 },
98 onDelete: 'set null'
99 })
100 ReplaySetting: VideoLiveReplaySettingModel
101
102 @BeforeDestroy
103 static deleteReplaySetting (instance: VideoLiveModel) {
104 return VideoLiveReplaySettingModel.destroy({
105 where: {
106 id: instance.replaySettingId
107 }
108 })
109 }
110
69 static loadByStreamKey (streamKey: string) { 111 static loadByStreamKey (streamKey: string) {
70 const query = { 112 const query = {
71 where: { 113 where: {
@@ -84,11 +126,15 @@ export class VideoLiveModel extends Model<Partial<AttributesOnly<VideoLiveModel>
84 required: false 126 required: false
85 } 127 }
86 ] 128 ]
129 },
130 {
131 model: VideoLiveReplaySettingModel.unscoped(),
132 required: false
87 } 133 }
88 ] 134 ]
89 } 135 }
90 136
91 return VideoLiveModel.findOne<MVideoLiveVideo>(query) 137 return VideoLiveModel.findOne<MVideoLiveVideoWithSetting>(query)
92 } 138 }
93 139
94 static loadByVideoId (videoId: number) { 140 static loadByVideoId (videoId: number) {
@@ -120,11 +166,16 @@ export class VideoLiveModel extends Model<Partial<AttributesOnly<VideoLiveModel>
120 } 166 }
121 } 167 }
122 168
169 const replaySettings = this.replaySettingId
170 ? this.ReplaySetting.toFormattedJSON()
171 : undefined
172
123 return { 173 return {
124 ...privateInformation, 174 ...privateInformation,
125 175
126 permanentLive: this.permanentLive, 176 permanentLive: this.permanentLive,
127 saveReplay: this.saveReplay, 177 saveReplay: this.saveReplay,
178 replaySettings,
128 latencyMode: this.latencyMode 179 latencyMode: this.latencyMode
129 } 180 }
130 } 181 }