From 05a60d85997c108d39bcfb14f1ffd4c74f8b1e93 Mon Sep 17 00:00:00 2001 From: Wicklow <123956049+wickloww@users.noreply.github.com> Date: Fri, 31 Mar 2023 07:12:21 +0000 Subject: 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 --- server/lib/job-queue/handlers/video-live-ending.ts | 15 ++++++++-- server/lib/live/live-manager.ts | 33 +++++++++++++++------- 2 files changed, 36 insertions(+), 12 deletions(-) (limited to 'server/lib') diff --git a/server/lib/job-queue/handlers/video-live-ending.ts b/server/lib/job-queue/handlers/video-live-ending.ts index c6263f55a..2f3a971bd 100644 --- a/server/lib/job-queue/handlers/video-live-ending.ts +++ b/server/lib/job-queue/handlers/video-live-ending.ts @@ -19,6 +19,7 @@ import { MVideo, MVideoLive, MVideoLiveSession, MVideoWithAllFiles } from '@serv import { ThumbnailType, VideoLiveEndingPayload, VideoState } from '@shared/models' import { logger, loggerTagsFactory } from '../../../helpers/logger' import { VideoPathManager } from '@server/lib/video-path-manager' +import { VideoLiveReplaySettingModel } from '@server/models/video/video-live-replay-setting' const lTags = loggerTagsFactory('live', 'job') @@ -60,7 +61,13 @@ async function processVideoLiveEnding (job: Job) { return cleanupLiveAndFederate({ permanentLive, video, streamingPlaylistId: payload.streamingPlaylistId }) } - return replaceLiveByReplay({ video, liveSession, live, permanentLive, replayDirectory: payload.replayDirectory }) + return replaceLiveByReplay({ + video, + liveSession, + live, + permanentLive, + replayDirectory: payload.replayDirectory + }) } // --------------------------------------------------------------------------- @@ -79,6 +86,8 @@ async function saveReplayToExternalVideo (options: { }) { const { liveVideo, liveSession, publishedAt, replayDirectory } = options + const replaySettings = await VideoLiveReplaySettingModel.load(liveSession.replaySettingId) + const replayVideo = new VideoModel({ name: `${liveVideo.name} - ${new Date(publishedAt).toLocaleString()}`, isLive: false, @@ -95,7 +104,7 @@ async function saveReplayToExternalVideo (options: { nsfw: liveVideo.nsfw, description: liveVideo.description, support: liveVideo.support, - privacy: liveVideo.privacy, + privacy: replaySettings.privacy, channelId: liveVideo.channelId }) as MVideoWithAllFiles @@ -142,6 +151,7 @@ async function replaceLiveByReplay (options: { }) { const { video, liveSession, live, permanentLive, replayDirectory } = options + const replaySettings = await VideoLiveReplaySettingModel.load(liveSession.replaySettingId) const videoWithFiles = await VideoModel.loadFull(video.id) const hlsPlaylist = videoWithFiles.getHLSPlaylist() @@ -150,6 +160,7 @@ async function replaceLiveByReplay (options: { await live.destroy() videoWithFiles.isLive = false + videoWithFiles.privacy = replaySettings.privacy videoWithFiles.waitTranscoding = true videoWithFiles.state = VideoState.TO_TRANSCODE diff --git a/server/lib/live/live-manager.ts b/server/lib/live/live-manager.ts index 1d5b8bf14..05274955d 100644 --- a/server/lib/live/live-manager.ts +++ b/server/lib/live/live-manager.ts @@ -19,7 +19,7 @@ import { VideoModel } from '@server/models/video/video' import { VideoLiveModel } from '@server/models/video/video-live' import { VideoLiveSessionModel } from '@server/models/video/video-live-session' import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist' -import { MVideo, MVideoLiveSession, MVideoLiveVideo } from '@server/types/models' +import { MVideo, MVideoLiveSession, MVideoLiveVideo, MVideoLiveVideoWithSetting } from '@server/types/models' import { pick, wait } from '@shared/core-utils' import { LiveVideoError, VideoState } from '@shared/models' import { federateVideoIfNeeded } from '../activitypub/videos' @@ -30,6 +30,8 @@ import { Hooks } from '../plugins/hooks' import { LiveQuotaStore } from './live-quota-store' import { cleanupAndDestroyPermanentLive } from './live-utils' import { MuxingSession } from './shared' +import { sequelizeTypescript } from '@server/initializers/database' +import { VideoLiveReplaySettingModel } from '@server/models/video/video-live-replay-setting' const NodeRtmpSession = require('node-media-server/src/node_rtmp_session') const context = require('node-media-server/src/node_core_ctx') @@ -270,7 +272,7 @@ class LiveManager { private async runMuxingSession (options: { sessionId: string - videoLive: MVideoLiveVideo + videoLive: MVideoLiveVideoWithSetting inputUrl: string fps: number @@ -470,15 +472,26 @@ class LiveManager { return resolutionsEnabled } - private saveStartingSession (videoLive: MVideoLiveVideo) { - const liveSession = new VideoLiveSessionModel({ - startDate: new Date(), - liveVideoId: videoLive.videoId, - saveReplay: videoLive.saveReplay, - endingProcessed: false - }) + private async saveStartingSession (videoLive: MVideoLiveVideoWithSetting) { + const replaySettings = videoLive.saveReplay + ? new VideoLiveReplaySettingModel({ + privacy: videoLive.ReplaySetting.privacy + }) + : null - return liveSession.save() + return sequelizeTypescript.transaction(async t => { + if (videoLive.saveReplay) { + await replaySettings.save({ transaction: t }) + } + + return VideoLiveSessionModel.create({ + startDate: new Date(), + liveVideoId: videoLive.videoId, + saveReplay: videoLive.saveReplay, + replaySettingId: videoLive.saveReplay ? replaySettings.id : null, + endingProcessed: false + }, { transaction: t }) + }) } private async saveEndingSession (videoId: number, error: LiveVideoError | null) { -- cgit v1.2.3