From 31ff8a8a1e5f6b42e66883e47b366b9e6942c74e Mon Sep 17 00:00:00 2001 From: Sergiy Date: Mon, 23 Sep 2024 23:58:39 +0300 Subject: [PATCH 1/3] OV-391: * remotion service --- backend/src/common/services/remotion/remotion.service.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/backend/src/common/services/remotion/remotion.service.ts b/backend/src/common/services/remotion/remotion.service.ts index 2a264362d..d4774e213 100644 --- a/backend/src/common/services/remotion/remotion.service.ts +++ b/backend/src/common/services/remotion/remotion.service.ts @@ -1,5 +1,6 @@ import { type AwsRegion, + deleteRender, getRenderProgress, renderMediaOnLambda, } from '@remotion/lambda/client'; @@ -21,6 +22,14 @@ class RemotionService { this.config.ENV.AWS.CLOUDFRONT.DOMAIN_ID_FOR_RENDERED_VIDEO; } + public async deleteRenderedVideo(renderId: string): Promise { + await deleteRender({ + bucketName: this.config.ENV.REMOTION.BUCKET_NAME, + region: this.config.ENV.AWS.S3.REGION as AwsRegion, + renderId, + }); + } + public async renderVideo( inputProperties: InputProperties, ): Promise { From 2077935c4aff31b07324a6eb57fd48054873b61a Mon Sep 17 00:00:00 2001 From: Sergiy Date: Tue, 24 Sep 2024 00:01:17 +0300 Subject: [PATCH 2/3] OV-391: * video service --- backend/src/bundles/videos/video.service.ts | 20 ++++++++++++++------ backend/src/bundles/videos/videos.ts | 4 ++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/backend/src/bundles/videos/video.service.ts b/backend/src/bundles/videos/video.service.ts index fad0bacb5..8dcc08867 100644 --- a/backend/src/bundles/videos/video.service.ts +++ b/backend/src/bundles/videos/video.service.ts @@ -1,7 +1,7 @@ import { VideoEntity } from '~/bundles/videos/video.entity.js'; import { type VideoRepository } from '~/bundles/videos/video.repository.js'; import { HTTPCode, HttpError } from '~/common/http/http.js'; -import { type FileService } from '~/common/services/file/file.service.js'; +import { type RemotionService } from '~/common/services/remotion/remotion.service.js'; import { type Service } from '~/common/types/types.js'; import { VideoValidationMessage } from './enums/enums.js'; @@ -14,14 +14,14 @@ import { class VideoService implements Service { private videoRepository: VideoRepository; - private fileService: FileService; + private remotionService: RemotionService; public constructor( videoRepository: VideoRepository, - fileService: FileService, + remotionService: RemotionService, ) { this.videoRepository = videoRepository; - this.fileService = fileService; + this.remotionService = remotionService; } public async findById(id: string): Promise { @@ -85,9 +85,17 @@ class VideoService implements Service { } public async delete(id: string): Promise { - const { name } = await this.findById(id); + const { url } = await this.findById(id); - await this.fileService.deleteFile(name); + if (url) { + const renderIdMatch = url.match(/renders\/([^/]+)/); + + if (renderIdMatch && renderIdMatch[1]) { + await this.remotionService.deleteRenderedVideo( + renderIdMatch[1], + ); + } + } const isVideoDeleted = await this.videoRepository.delete(id); diff --git a/backend/src/bundles/videos/videos.ts b/backend/src/bundles/videos/videos.ts index 133a4dcab..7be20cecf 100644 --- a/backend/src/bundles/videos/videos.ts +++ b/backend/src/bundles/videos/videos.ts @@ -1,5 +1,5 @@ import { logger } from '~/common/logger/logger.js'; -import { fileService } from '~/common/services/services.js'; +import { remotionService } from '~/common/services/services.js'; import { VideoController } from './video.controller.js'; import { VideoModel } from './video.model.js'; @@ -7,7 +7,7 @@ import { VideoRepository } from './video.repository.js'; import { VideoService } from './video.service.js'; const videoRepository = new VideoRepository(VideoModel); -const videoService = new VideoService(videoRepository, fileService); +const videoService = new VideoService(videoRepository, remotionService); const videoController = new VideoController(logger, videoService); export { videoController, videoService }; From 4b612d44a5ada1668a4d739d70d6ff8c7e53abcd Mon Sep 17 00:00:00 2001 From: Sergiy Date: Wed, 25 Sep 2024 15:09:53 +0300 Subject: [PATCH 3/3] OV-391: * video service --- backend/src/bundles/videos/video.service.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/backend/src/bundles/videos/video.service.ts b/backend/src/bundles/videos/video.service.ts index 8dcc08867..f40ef682d 100644 --- a/backend/src/bundles/videos/video.service.ts +++ b/backend/src/bundles/videos/video.service.ts @@ -89,11 +89,10 @@ class VideoService implements Service { if (url) { const renderIdMatch = url.match(/renders\/([^/]+)/); + const renderId = renderIdMatch?.[1]; - if (renderIdMatch && renderIdMatch[1]) { - await this.remotionService.deleteRenderedVideo( - renderIdMatch[1], - ); + if (renderId) { + await this.remotionService.deleteRenderedVideo(renderId); } }