aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos/live.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/videos/live.ts')
-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