diff --git a/backend/src/bundles/videos/video.service.ts b/backend/src/bundles/videos/video.service.ts index fad0bacb5..f40ef682d 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,16 @@ 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\/([^/]+)/); + const renderId = renderIdMatch?.[1]; + + if (renderId) { + await this.remotionService.deleteRenderedVideo(renderId); + } + } 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 }; diff --git a/backend/src/common/services/remotion/remotion.service.ts b/backend/src/common/services/remotion/remotion.service.ts index f600b5405..14ea06d26 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'; @@ -27,6 +28,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 {