Skip to content

Commit

Permalink
Merge pull request #395 from BinaryStudioAcademy/task/OV-391-add-logi…
Browse files Browse the repository at this point in the history
…c-to-delete-video

OV-391: add logic to delete video
  • Loading branch information
sofiia-trokhymchuk authored Sep 26, 2024
2 parents 243ce54 + 4b612d4 commit 59850e9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
19 changes: 13 additions & 6 deletions backend/src/bundles/videos/video.service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<VideoGetAllItemResponseDto> {
Expand Down Expand Up @@ -85,9 +85,16 @@ class VideoService implements Service {
}

public async delete(id: string): Promise<boolean> {
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);

Expand Down
4 changes: 2 additions & 2 deletions backend/src/bundles/videos/videos.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
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';
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 };
9 changes: 9 additions & 0 deletions backend/src/common/services/remotion/remotion.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
type AwsRegion,
deleteRender,
getRenderProgress,
renderMediaOnLambda,
} from '@remotion/lambda/client';
Expand Down Expand Up @@ -27,6 +28,14 @@ class RemotionService {
this.config.ENV.AWS.CLOUDFRONT.DOMAIN_ID_FOR_RENDERED_VIDEO;
}

public async deleteRenderedVideo(renderId: string): Promise<void> {
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<string> {
Expand Down

0 comments on commit 59850e9

Please sign in to comment.