mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 10:49:28 +02:00
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
This commit is contained in:
parent
ebd61437c1
commit
05a60d8599
36 changed files with 746 additions and 120 deletions
|
@ -16,7 +16,7 @@ import {
|
|||
} from '@server/middlewares/validators/videos/video-live'
|
||||
import { VideoLiveModel } from '@server/models/video/video-live'
|
||||
import { VideoLiveSessionModel } from '@server/models/video/video-live-session'
|
||||
import { MVideoDetails, MVideoFullLight } from '@server/types/models'
|
||||
import { MVideoDetails, MVideoFullLight, MVideoLive } from '@server/types/models'
|
||||
import { buildUUID, uuidToShort } from '@shared/extra-utils'
|
||||
import { HttpStatusCode, LiveVideoCreate, LiveVideoLatencyMode, LiveVideoUpdate, UserRight, VideoState } from '@shared/models'
|
||||
import { logger } from '../../../helpers/logger'
|
||||
|
@ -24,6 +24,7 @@ import { sequelizeTypescript } from '../../../initializers/database'
|
|||
import { updateVideoMiniatureFromExisting } from '../../../lib/thumbnail'
|
||||
import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, optionalAuthenticate } from '../../../middlewares'
|
||||
import { VideoModel } from '../../../models/video/video'
|
||||
import { VideoLiveReplaySettingModel } from '@server/models/video/video-live-replay-setting'
|
||||
|
||||
const liveRouter = express.Router()
|
||||
|
||||
|
@ -105,7 +106,10 @@ async function updateLiveVideo (req: express.Request, res: express.Response) {
|
|||
const video = res.locals.videoAll
|
||||
const videoLive = res.locals.videoLive
|
||||
|
||||
if (exists(body.saveReplay)) videoLive.saveReplay = body.saveReplay
|
||||
const newReplaySettingModel = await updateReplaySettings(videoLive, body)
|
||||
if (newReplaySettingModel) videoLive.replaySettingId = newReplaySettingModel.id
|
||||
else videoLive.replaySettingId = null
|
||||
|
||||
if (exists(body.permanentLive)) videoLive.permanentLive = body.permanentLive
|
||||
if (exists(body.latencyMode)) videoLive.latencyMode = body.latencyMode
|
||||
|
||||
|
@ -116,6 +120,27 @@ async function updateLiveVideo (req: express.Request, res: express.Response) {
|
|||
return res.status(HttpStatusCode.NO_CONTENT_204).end()
|
||||
}
|
||||
|
||||
async function updateReplaySettings (videoLive: MVideoLive, body: LiveVideoUpdate) {
|
||||
if (exists(body.saveReplay)) videoLive.saveReplay = body.saveReplay
|
||||
|
||||
// The live replay is not saved anymore, destroy the old model if it existed
|
||||
if (!videoLive.saveReplay) {
|
||||
if (videoLive.replaySettingId) {
|
||||
await VideoLiveReplaySettingModel.removeSettings(videoLive.replaySettingId)
|
||||
}
|
||||
|
||||
return undefined
|
||||
}
|
||||
|
||||
const settingModel = videoLive.replaySettingId
|
||||
? await VideoLiveReplaySettingModel.load(videoLive.replaySettingId)
|
||||
: new VideoLiveReplaySettingModel()
|
||||
|
||||
if (exists(body.replaySettings.privacy)) settingModel.privacy = body.replaySettings.privacy
|
||||
|
||||
return settingModel.save()
|
||||
}
|
||||
|
||||
async function addLiveVideo (req: express.Request, res: express.Response) {
|
||||
const videoInfo: LiveVideoCreate = req.body
|
||||
|
||||
|
@ -161,6 +186,15 @@ async function addLiveVideo (req: express.Request, res: express.Response) {
|
|||
// Do not forget to add video channel information to the created video
|
||||
videoCreated.VideoChannel = res.locals.videoChannel
|
||||
|
||||
if (videoLive.saveReplay) {
|
||||
const replaySettings = new VideoLiveReplaySettingModel({
|
||||
privacy: videoInfo.replaySettings.privacy
|
||||
})
|
||||
await replaySettings.save(sequelizeOptions)
|
||||
|
||||
videoLive.replaySettingId = replaySettings.id
|
||||
}
|
||||
|
||||
videoLive.videoId = videoCreated.id
|
||||
videoCreated.VideoLive = await videoLive.save(sequelizeOptions)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue