From 501b0673355a548f4102d3eacf644797d89fe4af Mon Sep 17 00:00:00 2001 From: Oleksandra Okhotnykova Date: Thu, 26 Sep 2024 13:55:06 +0200 Subject: [PATCH] OV-423: * pass scene instead of composition --- backend/src/bundles/videos/types/types.ts | 1 + backend/src/bundles/videos/video.repository.ts | 7 +++++-- backend/src/bundles/videos/video.service.ts | 3 ++- backend/src/common/services/image/image.service.ts | 8 ++++---- backend/src/common/services/image/types/types.ts | 2 +- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/backend/src/bundles/videos/types/types.ts b/backend/src/bundles/videos/types/types.ts index 0e99b9510..86eea3daa 100644 --- a/backend/src/bundles/videos/types/types.ts +++ b/backend/src/bundles/videos/types/types.ts @@ -1,5 +1,6 @@ export { type CreateVideoRequestDto, + type Scene, type UpdateVideoRequestDto, type UserGetCurrentResponseDto, type VideoGetAllItemResponseDto, diff --git a/backend/src/bundles/videos/video.repository.ts b/backend/src/bundles/videos/video.repository.ts index 8e56b2730..ed0b8bc91 100644 --- a/backend/src/bundles/videos/video.repository.ts +++ b/backend/src/bundles/videos/video.repository.ts @@ -1,4 +1,7 @@ -import { type UpdateVideoRequestDto } from '~/bundles/videos/types/types.js'; +import { + type Scene, + type UpdateVideoRequestDto, +} from '~/bundles/videos/types/types.js'; import { VideoEntity } from '~/bundles/videos/video.entity.js'; import { type VideoModel } from '~/bundles/videos/video.model.js'; import { type ImageService } from '~/common/services/image/image.service.js'; @@ -65,7 +68,7 @@ class VideoRepository implements Repository { if (payload.composition) { data.composition = payload.composition; data.previewUrl = await this.imageService.generatePreview( - payload.composition, + payload.composition.scenes[0] as Scene, ); } diff --git a/backend/src/bundles/videos/video.service.ts b/backend/src/bundles/videos/video.service.ts index 1745497db..dc31ddc87 100644 --- a/backend/src/bundles/videos/video.service.ts +++ b/backend/src/bundles/videos/video.service.ts @@ -8,6 +8,7 @@ import { type Service } from '~/common/types/types.js'; import { VideoValidationMessage } from './enums/enums.js'; import { type CreateVideoRequestDto, + type Scene, type UpdateVideoRequestDto, type VideoGetAllItemResponseDto, type VideoGetAllResponseDto, @@ -61,7 +62,7 @@ class VideoService implements Service { payload: CreateVideoRequestDto & { userId: string }, ): Promise { const previewUrl = await this.imageService.generatePreview( - payload.composition, + payload.composition.scenes[0] as Scene, ); const video = await this.videoRepository.create( diff --git a/backend/src/common/services/image/image.service.ts b/backend/src/common/services/image/image.service.ts index a84c3f745..6cb0b6a9b 100644 --- a/backend/src/common/services/image/image.service.ts +++ b/backend/src/common/services/image/image.service.ts @@ -4,7 +4,7 @@ import { type FileService } from '~/common/services/file/file.service.js'; import { PREVIEW_HEIGHT, PREVIEW_WIDTH } from './constants/constants.js'; import { type ImageApi } from './image-base.js'; -import { type Composition } from './types/types.js'; +import { type Scene } from './types/types.js'; type Constructor = { fileService: FileService; @@ -20,9 +20,9 @@ class ImageService { this.imageApi = imageApi; } - public async generatePreview(composition: Composition): Promise { - const avatarImage = composition.scenes[0]?.avatar?.url ?? ''; - const background = composition.scenes[0]?.background; + public async generatePreview(scene: Scene): Promise { + const avatarImage = scene.avatar?.url ?? ''; + const background = scene.background; if (background?.url) { const backgroundImageBuffer = await this.imageApi.getImageBuffer( diff --git a/backend/src/common/services/image/types/types.ts b/backend/src/common/services/image/types/types.ts index 91ee6dd10..23de6349e 100644 --- a/backend/src/common/services/image/types/types.ts +++ b/backend/src/common/services/image/types/types.ts @@ -1 +1 @@ -export { type Composition } from 'shared'; +export { type Scene } from 'shared';