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-session.ts | 49 ++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'server/models/video/video-live-session.ts') diff --git a/server/models/video/video-live-session.ts b/server/models/video/video-live-session.ts index ed386052b..dcded7872 100644 --- a/server/models/video/video-live-session.ts +++ b/server/models/video/video-live-session.ts @@ -1,10 +1,23 @@ import { FindOptions } from 'sequelize' -import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' +import { + AllowNull, + BeforeDestroy, + BelongsTo, + Column, + CreatedAt, + DataType, + ForeignKey, + Model, + Scopes, + Table, + UpdatedAt +} from 'sequelize-typescript' import { MVideoLiveSession, MVideoLiveSessionReplay } from '@server/types/models' import { uuidToShort } from '@shared/extra-utils' import { LiveVideoError, LiveVideoSession } from '@shared/models' import { AttributesOnly } from '@shared/typescript-utils' import { VideoModel } from './video' +import { VideoLiveReplaySettingModel } from './video-live-replay-setting' export enum ScopeNames { WITH_REPLAY = 'WITH_REPLAY' @@ -17,6 +30,10 @@ export enum ScopeNames { model: VideoModel.unscoped(), as: 'ReplayVideo', required: false + }, + { + model: VideoLiveReplaySettingModel, + required: false } ] } @@ -30,6 +47,10 @@ export enum ScopeNames { }, { fields: [ 'liveVideoId' ] + }, + { + fields: [ 'replaySettingId' ], + unique: true } ] }) @@ -89,6 +110,27 @@ export class VideoLiveSessionModel extends Model VideoLiveReplaySettingModel) + @Column + replaySettingId: number + + @BelongsTo(() => VideoLiveReplaySettingModel, { + foreignKey: { + allowNull: true + }, + onDelete: 'set null' + }) + ReplaySetting: VideoLiveReplaySettingModel + + @BeforeDestroy + static deleteReplaySetting (instance: VideoLiveSessionModel) { + return VideoLiveReplaySettingModel.destroy({ + where: { + id: instance.replaySettingId + } + }) + } + static load (id: number): Promise { return VideoLiveSessionModel.findOne({ where: { id } @@ -146,6 +188,10 @@ export class VideoLiveSessionModel extends Model