aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos
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/controllers/api/videos
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/controllers/api/videos')
-rw-r--r--server/controllers/api/videos/live.ts38
1 files changed, 36 insertions, 2 deletions
diff --git a/server/controllers/api/videos/live.ts b/server/controllers/api/videos/live.ts
index ec4c073b5..de047d4ec 100644
--- a/server/controllers/api/videos/live.ts
+++ b/server/controllers/api/videos/live.ts
@@ -16,7 +16,7 @@ import {
16} from '@server/middlewares/validators/videos/video-live' 16} from '@server/middlewares/validators/videos/video-live'
17import { VideoLiveModel } from '@server/models/video/video-live' 17import { VideoLiveModel } from '@server/models/video/video-live'
18import { VideoLiveSessionModel } from '@server/models/video/video-live-session' 18import { VideoLiveSessionModel } from '@server/models/video/video-live-session'
19import { MVideoDetails, MVideoFullLight } from '@server/types/models' 19import { MVideoDetails, MVideoFullLight, MVideoLive } from '@server/types/models'
20import { buildUUID, uuidToShort } from '@shared/extra-utils' 20import { buildUUID, uuidToShort } from '@shared/extra-utils'
21import { HttpStatusCode, LiveVideoCreate, LiveVideoLatencyMode, LiveVideoUpdate, UserRight, VideoState } from '@shared/models' 21import { HttpStatusCode, LiveVideoCreate, LiveVideoLatencyMode, LiveVideoUpdate, UserRight, VideoState } from '@shared/models'
22import { logger } from '../../../helpers/logger' 22import { logger } from '../../../helpers/logger'
@@ -24,6 +24,7 @@ import { sequelizeTypescript } from '../../../initializers/database'
24import { updateVideoMiniatureFromExisting } from '../../../lib/thumbnail' 24import { updateVideoMiniatureFromExisting } from '../../../lib/thumbnail'
25import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, optionalAuthenticate } from '../../../middlewares' 25import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, optionalAuthenticate } from '../../../middlewares'
26import { VideoModel } from '../../../models/video/video' 26import { VideoModel } from '../../../models/video/video'
27import { VideoLiveReplaySettingModel } from '@server/models/video/video-live-replay-setting'
27 28
28const liveRouter = express.Router() 29const liveRouter = express.Router()
29 30
@@ -105,7 +106,10 @@ async function updateLiveVideo (req: express.Request, res: express.Response) {
105 const video = res.locals.videoAll 106 const video = res.locals.videoAll
106 const videoLive = res.locals.videoLive 107 const videoLive = res.locals.videoLive
107 108
108 if (exists(body.saveReplay)) videoLive.saveReplay = body.saveReplay 109 const newReplaySettingModel = await updateReplaySettings(videoLive, body)
110 if (newReplaySettingModel) videoLive.replaySettingId = newReplaySettingModel.id
111 else videoLive.replaySettingId = null
112
109 if (exists(body.permanentLive)) videoLive.permanentLive = body.permanentLive 113 if (exists(body.permanentLive)) videoLive.permanentLive = body.permanentLive
110 if (exists(body.latencyMode)) videoLive.latencyMode = body.latencyMode 114 if (exists(body.latencyMode)) videoLive.latencyMode = body.latencyMode
111 115
@@ -116,6 +120,27 @@ async function updateLiveVideo (req: express.Request, res: express.Response) {
116 return res.status(HttpStatusCode.NO_CONTENT_204).end() 120 return res.status(HttpStatusCode.NO_CONTENT_204).end()
117} 121}
118 122
123async function updateReplaySettings (videoLive: MVideoLive, body: LiveVideoUpdate) {
124 if (exists(body.saveReplay)) videoLive.saveReplay = body.saveReplay
125
126 // The live replay is not saved anymore, destroy the old model if it existed
127 if (!videoLive.saveReplay) {
128 if (videoLive.replaySettingId) {
129 await VideoLiveReplaySettingModel.removeSettings(videoLive.replaySettingId)
130 }
131
132 return undefined
133 }
134
135 const settingModel = videoLive.replaySettingId
136 ? await VideoLiveReplaySettingModel.load(videoLive.replaySettingId)
137 : new VideoLiveReplaySettingModel()
138
139 if (exists(body.replaySettings.privacy)) settingModel.privacy = body.replaySettings.privacy
140
141 return settingModel.save()
142}
143
119async function addLiveVideo (req: express.Request, res: express.Response) { 144async function addLiveVideo (req: express.Request, res: express.Response) {
120 const videoInfo: LiveVideoCreate = req.body 145 const videoInfo: LiveVideoCreate = req.body
121 146
@@ -161,6 +186,15 @@ async function addLiveVideo (req: express.Request, res: express.Response) {
161 // Do not forget to add video channel information to the created video 186 // Do not forget to add video channel information to the created video
162 videoCreated.VideoChannel = res.locals.videoChannel 187 videoCreated.VideoChannel = res.locals.videoChannel
163 188
189 if (videoLive.saveReplay) {
190 const replaySettings = new VideoLiveReplaySettingModel({
191 privacy: videoInfo.replaySettings.privacy
192 })
193 await replaySettings.save(sequelizeOptions)
194
195 videoLive.replaySettingId = replaySettings.id
196 }
197
164 videoLive.videoId = videoCreated.id 198 videoLive.videoId = videoCreated.id
165 videoCreated.VideoLive = await videoLive.save(sequelizeOptions) 199 videoCreated.VideoLive = await videoLive.save(sequelizeOptions)
166 200