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/models/video/video-live.ts | 57 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 3 deletions(-) (limited to 'server/models/video/video-live.ts') diff --git a/server/models/video/video-live.ts b/server/models/video/video-live.ts index d2788ef4f..290e1dda7 100644 --- a/server/models/video/video-live.ts +++ b/server/models/video/video-live.ts @@ -1,11 +1,24 @@ -import { AllowNull, BelongsTo, Column, CreatedAt, DataType, DefaultScope, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript' +import { + BeforeDestroy, + AllowNull, + BelongsTo, + Column, + CreatedAt, + DataType, + DefaultScope, + ForeignKey, + Model, + Table, + UpdatedAt +} from 'sequelize-typescript' import { CONFIG } from '@server/initializers/config' import { WEBSERVER } from '@server/initializers/constants' -import { MVideoLive, MVideoLiveVideo } from '@server/types/models' +import { MVideoLive, MVideoLiveVideoWithSetting } from '@server/types/models' import { LiveVideo, LiveVideoLatencyMode, VideoState } from '@shared/models' import { AttributesOnly } from '@shared/typescript-utils' import { VideoModel } from './video' import { VideoBlacklistModel } from './video-blacklist' +import { VideoLiveReplaySettingModel } from './video-live-replay-setting' @DefaultScope(() => ({ include: [ @@ -18,6 +31,10 @@ import { VideoBlacklistModel } from './video-blacklist' required: false } ] + }, + { + model: VideoLiveReplaySettingModel, + required: false } ] })) @@ -27,6 +44,10 @@ import { VideoBlacklistModel } from './video-blacklist' { fields: [ 'videoId' ], unique: true + }, + { + fields: [ 'replaySettingId' ], + unique: true } ] }) @@ -66,6 +87,27 @@ export class VideoLiveModel extends Model }) Video: VideoModel + @ForeignKey(() => VideoLiveReplaySettingModel) + @Column + replaySettingId: number + + @BelongsTo(() => VideoLiveReplaySettingModel, { + foreignKey: { + allowNull: true + }, + onDelete: 'set null' + }) + ReplaySetting: VideoLiveReplaySettingModel + + @BeforeDestroy + static deleteReplaySetting (instance: VideoLiveModel) { + return VideoLiveReplaySettingModel.destroy({ + where: { + id: instance.replaySettingId + } + }) + } + static loadByStreamKey (streamKey: string) { const query = { where: { @@ -84,11 +126,15 @@ export class VideoLiveModel extends Model required: false } ] + }, + { + model: VideoLiveReplaySettingModel.unscoped(), + required: false } ] } - return VideoLiveModel.findOne(query) + return VideoLiveModel.findOne(query) } static loadByVideoId (videoId: number) { @@ -120,11 +166,16 @@ export class VideoLiveModel extends Model } } + const replaySettings = this.replaySettingId + ? this.ReplaySetting.toFormattedJSON() + : undefined + return { ...privateInformation, permanentLive: this.permanentLive, saveReplay: this.saveReplay, + replaySettings, latencyMode: this.latencyMode } } -- cgit v1.2.3