diff options
author | Wicklow <123956049+wickloww@users.noreply.github.com> | 2023-03-31 07:12:21 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-31 09:12:21 +0200 |
commit | 05a60d85997c108d39bcfb14f1ffd4c74f8b1e93 (patch) | |
tree | 5041a95ef945620a17f25ba934064b41f6bb00b7 /server/controllers/api/videos | |
parent | ebd61437c1ec92bea9772924c7051cb00d71f778 (diff) | |
download | PeerTube-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.ts | 38 |
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' |
17 | import { VideoLiveModel } from '@server/models/video/video-live' | 17 | import { VideoLiveModel } from '@server/models/video/video-live' |
18 | import { VideoLiveSessionModel } from '@server/models/video/video-live-session' | 18 | import { VideoLiveSessionModel } from '@server/models/video/video-live-session' |
19 | import { MVideoDetails, MVideoFullLight } from '@server/types/models' | 19 | import { MVideoDetails, MVideoFullLight, MVideoLive } from '@server/types/models' |
20 | import { buildUUID, uuidToShort } from '@shared/extra-utils' | 20 | import { buildUUID, uuidToShort } from '@shared/extra-utils' |
21 | import { HttpStatusCode, LiveVideoCreate, LiveVideoLatencyMode, LiveVideoUpdate, UserRight, VideoState } from '@shared/models' | 21 | import { HttpStatusCode, LiveVideoCreate, LiveVideoLatencyMode, LiveVideoUpdate, UserRight, VideoState } from '@shared/models' |
22 | import { logger } from '../../../helpers/logger' | 22 | import { logger } from '../../../helpers/logger' |
@@ -24,6 +24,7 @@ import { sequelizeTypescript } from '../../../initializers/database' | |||
24 | import { updateVideoMiniatureFromExisting } from '../../../lib/thumbnail' | 24 | import { updateVideoMiniatureFromExisting } from '../../../lib/thumbnail' |
25 | import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, optionalAuthenticate } from '../../../middlewares' | 25 | import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, optionalAuthenticate } from '../../../middlewares' |
26 | import { VideoModel } from '../../../models/video/video' | 26 | import { VideoModel } from '../../../models/video/video' |
27 | import { VideoLiveReplaySettingModel } from '@server/models/video/video-live-replay-setting' | ||
27 | 28 | ||
28 | const liveRouter = express.Router() | 29 | const 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 | ||
123 | async 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 | |||
119 | async function addLiveVideo (req: express.Request, res: express.Response) { | 144 | async 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 | ||