Skip to content

Commit

Permalink
Merge pull request #379 from BinaryStudioAcademy/task/OV-378-fix-down…
Browse files Browse the repository at this point in the history
…load-video

OV-378: fix download video
  • Loading branch information
nikita-remeslov authored Sep 24, 2024
2 parents 4384043 + b53f742 commit df77998
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 5 deletions.
23 changes: 19 additions & 4 deletions backend/src/bundles/avatar-videos/avatar-videos.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,29 @@ class AvatarVideoService {
const url =
await this.remotionService.getRemotionRenderProgress(renderId);

if (url) {
// TODO: NOTIFY USER
await this.updateVideoRecord(videoRecordId, url);
}

await this.removeGeneratedAvatars(scenesWithSavedAvatars);
await this.removeAvatarsFromBucket(scenesWithSavedAvatars);
}

private async updateVideoRecord(
videoRecordId: string,
videoUrl: string,
): Promise<void> {
const videoData = await this.videoService.update(videoRecordId, {
url: videoUrl,
});

if (!url) {
return;
if (!videoData) {
throw new HttpError({
message: RenderVideoErrorMessage.NOT_SAVED,
status: HTTPCode.BAD_REQUEST,
});
}
// TODO: NOTIFY USER
await this.videoService.update(videoRecordId, { url });
}

private async removeGeneratedAvatars(
Expand Down
2 changes: 2 additions & 0 deletions backend/src/common/services/remotion/constants/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export { CODEC } from './codec.constant.js';
export { COMPOSITION_ID } from './composition-id.constant.js';
export { DOWNLOAD_BEHAVIOR } from './download-behavior.constant.js';
export { DOWNLOADED_FILE_NAME } from './downloaded-file-name.constant.js';
export { REQUEST_DELAY } from './request-delay.constant.js';
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const DOWNLOAD_BEHAVIOR = 'download';

export { DOWNLOAD_BEHAVIOR };
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const DOWNLOADED_FILE_NAME = 'download.mp4';

export { DOWNLOADED_FILE_NAME };
12 changes: 11 additions & 1 deletion backend/src/common/services/remotion/remotion.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import { HTTPCode, HttpError } from 'shared';
import { RenderVideoErrorMessage } from '~/bundles/avatar-videos/enums/enums.js';
import { type BaseConfig } from '~/common/config/base-config.package.js';

import { CODEC, COMPOSITION_ID, REQUEST_DELAY } from './constants/constants.js';
import {
CODEC,
COMPOSITION_ID,
DOWNLOAD_BEHAVIOR,
DOWNLOADED_FILE_NAME,
REQUEST_DELAY,
} from './constants/constants.js';
import { type InputProps as InputProperties } from './type/types.js';

class RemotionService {
Expand All @@ -25,6 +31,10 @@ class RemotionService {
inputProperties: InputProperties,
): Promise<string> {
const { renderId } = await renderMediaOnLambda({
downloadBehavior: {
type: DOWNLOAD_BEHAVIOR,
fileName: DOWNLOADED_FILE_NAME,
},
region: this.config.ENV.AWS.S3.REGION as AwsRegion,
functionName: this.config.ENV.REMOTION.LAMBDA_FUNCTION_NAME,
composition: COMPOSITION_ID,
Expand Down

0 comments on commit df77998

Please sign in to comment.