aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video-live-session.ts
diff options
context:
space:
mode:
authorWicklow <123956049+wickloww@users.noreply.github.com>2023-03-31 07:12:21 +0000
committerGitHub <noreply@github.com>2023-03-31 09:12:21 +0200
commit05a60d85997c108d39bcfb14f1ffd4c74f8b1e93 (patch)
tree5041a95ef945620a17f25ba934064b41f6bb00b7 /server/models/video/video-live-session.ts
parentebd61437c1ec92bea9772924c7051cb00d71f778 (diff)
downloadPeerTube-05a60d85997c108d39bcfb14f1ffd4c74f8b1e93.tar.gz
PeerTube-05a60d85997c108d39bcfb14f1ffd4c74f8b1e93.tar.zst
PeerTube-05a60d85997c108d39bcfb14f1ffd4c74f8b1e93.zip
Feature/Add replay privacy (#5692)
* Add replay settings feature * Fix replay settings behaviour * Fix tests * Fix tests * Fix tests * Update openapi doc and fix tests * Add tests and fix code * Models correction * Add migration and update controller and middleware * Add check params tests * Fix video live middleware * Updated code based on review comments
Diffstat (limited to 'server/models/video/video-live-session.ts')
-rw-r--r--server/models/video/video-live-session.ts49
1 files changed, 48 insertions, 1 deletions
diff --git a/server/models/video/video-live-session.ts b/server/models/video/video-live-session.ts
index ed386052b..dcded7872 100644
--- a/server/models/video/video-live-session.ts
+++ b/server/models/video/video-live-session.ts
@@ -1,10 +1,23 @@
1import { FindOptions } from 'sequelize' 1import { FindOptions } from 'sequelize'
2import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' 2import {
3 AllowNull,
4 BeforeDestroy,
5 BelongsTo,
6 Column,
7 CreatedAt,
8 DataType,
9 ForeignKey,
10 Model,
11 Scopes,
12 Table,
13 UpdatedAt
14} from 'sequelize-typescript'
3import { MVideoLiveSession, MVideoLiveSessionReplay } from '@server/types/models' 15import { MVideoLiveSession, MVideoLiveSessionReplay } from '@server/types/models'
4import { uuidToShort } from '@shared/extra-utils' 16import { uuidToShort } from '@shared/extra-utils'
5import { LiveVideoError, LiveVideoSession } from '@shared/models' 17import { LiveVideoError, LiveVideoSession } from '@shared/models'
6import { AttributesOnly } from '@shared/typescript-utils' 18import { AttributesOnly } from '@shared/typescript-utils'
7import { VideoModel } from './video' 19import { VideoModel } from './video'
20import { VideoLiveReplaySettingModel } from './video-live-replay-setting'
8 21
9export enum ScopeNames { 22export enum ScopeNames {
10 WITH_REPLAY = 'WITH_REPLAY' 23 WITH_REPLAY = 'WITH_REPLAY'
@@ -17,6 +30,10 @@ export enum ScopeNames {
17 model: VideoModel.unscoped(), 30 model: VideoModel.unscoped(),
18 as: 'ReplayVideo', 31 as: 'ReplayVideo',
19 required: false 32 required: false
33 },
34 {
35 model: VideoLiveReplaySettingModel,
36 required: false
20 } 37 }
21 ] 38 ]
22 } 39 }
@@ -30,6 +47,10 @@ export enum ScopeNames {
30 }, 47 },
31 { 48 {
32 fields: [ 'liveVideoId' ] 49 fields: [ 'liveVideoId' ]
50 },
51 {
52 fields: [ 'replaySettingId' ],
53 unique: true
33 } 54 }
34 ] 55 ]
35}) 56})
@@ -89,6 +110,27 @@ export class VideoLiveSessionModel extends Model<Partial<AttributesOnly<VideoLiv
89 }) 110 })
90 LiveVideo: VideoModel 111 LiveVideo: VideoModel
91 112
113 @ForeignKey(() => VideoLiveReplaySettingModel)
114 @Column
115 replaySettingId: number
116
117 @BelongsTo(() => VideoLiveReplaySettingModel, {
118 foreignKey: {
119 allowNull: true
120 },
121 onDelete: 'set null'
122 })
123 ReplaySetting: VideoLiveReplaySettingModel
124
125 @BeforeDestroy
126 static deleteReplaySetting (instance: VideoLiveSessionModel) {
127 return VideoLiveReplaySettingModel.destroy({
128 where: {
129 id: instance.replaySettingId
130 }
131 })
132 }
133
92 static load (id: number): Promise<MVideoLiveSession> { 134 static load (id: number): Promise<MVideoLiveSession> {
93 return VideoLiveSessionModel.findOne({ 135 return VideoLiveSessionModel.findOne({
94 where: { id } 136 where: { id }
@@ -146,6 +188,10 @@ export class VideoLiveSessionModel extends Model<Partial<AttributesOnly<VideoLiv
146 } 188 }
147 : undefined 189 : undefined
148 190
191 const replaySettings = this.replaySettingId
192 ? this.ReplaySetting.toFormattedJSON()
193 : undefined
194
149 return { 195 return {
150 id: this.id, 196 id: this.id,
151 startDate: this.startDate.toISOString(), 197 startDate: this.startDate.toISOString(),
@@ -154,6 +200,7 @@ export class VideoLiveSessionModel extends Model<Partial<AttributesOnly<VideoLiv
154 : null, 200 : null,
155 endingProcessed: this.endingProcessed, 201 endingProcessed: this.endingProcessed,
156 saveReplay: this.saveReplay, 202 saveReplay: this.saveReplay,
203 replaySettings,
157 replayVideo, 204 replayVideo,
158 error: this.error 205 error: this.error
159 } 206 }