🎥 Make videos programmatically with React
mock head command
Jonny Burgeradc45148eecb
diff --git a/packages/lambda/src/functions/helpers/__mocks__/io.ts b/packages/lambda/src/functions/helpers/__mocks__/io.tsindex 0fbdcdbd7b..1879293927 100644--- a/packages/lambda/src/functions/helpers/__mocks__/io.ts+++ b/packages/lambda/src/functions/helpers/__mocks__/io.ts@@ -8,6 +8,7 @@ import {} from '../../../api/__mocks__/mock-s3';import type {lambdaDeleteFile as deleteOriginal,+ lambdaHeadCommand as headOriginal,lambdaLs as lsOriginal,lambdaReadFile as readOriginal,lambdaWriteFile as writeOriginal,@@ -61,6 +62,22 @@ export const lambdaDeleteFile: typeof deleteOriginal = ({return Promise.resolve(undefined);};+export const lambdaHeadCommand: typeof headOriginal = ({+ bucketName,+ key,+ region,+}) => {+ const read = readMockS3File({+ bucketName,+ key,+ region,+ });+ return Promise.resolve({+ ContentLength: read?.content.toString().length,+ LastModified: new Date(),+ });+};+export const lambdaLs: typeof lsOriginal = (input: LambdaLSInput): LambdaLsReturnType => {diff --git a/packages/lambda/src/functions/helpers/find-output-file-in-bucket.ts b/packages/lambda/src/functions/helpers/find-output-file-in-bucket.tsindex 75fc29feb5..966860b9b9 100644--- a/packages/lambda/src/functions/helpers/find-output-file-in-bucket.ts+++ b/packages/lambda/src/functions/helpers/find-output-file-in-bucket.ts@@ -1,11 +1,10 @@-import {HeadObjectCommand} from '@aws-sdk/client-s3';import type {AwsRegion} from '../..';import {ROLE_NAME} from '../../api/iam-validation/suggested-policy';import type {CustomCredentials} from '../../shared/aws-clients';-import {getS3Client} from '../../shared/aws-clients';import type {RenderMetadata} from '../../shared/constants';import {getExpectedOutName} from './expected-out-name';import {getOutputUrlFromMetadata} from './get-output-url-from-metadata';+import {lambdaHeadCommand} from './io';export type OutputFileMetadata = {url: string;@@ -35,12 +34,11 @@ export const findOutputFileInBucket = async ({);try {- const head = await getS3Client(region, customCredentials).send(- new HeadObjectCommand({- Bucket: renderBucketName,- Key: key,- })- );+ const head = await lambdaHeadCommand({+ bucketName,+ key,+ region,+ });return {lastModified: head.LastModified?.getTime() as number,size: head.ContentLength as number,diff --git a/packages/lambda/src/functions/helpers/io.ts b/packages/lambda/src/functions/helpers/io.tsindex 8c8b110561..29a2d6e814 100644--- a/packages/lambda/src/functions/helpers/io.ts+++ b/packages/lambda/src/functions/helpers/io.ts@@ -2,6 +2,7 @@ import type {_Object} from '@aws-sdk/client-s3';import {DeleteObjectCommand,GetObjectCommand,+ HeadObjectCommand,ListObjectsV2Command,PutObjectCommand,} from '@aws-sdk/client-s3';@@ -152,3 +153,24 @@ export const lambdaReadFile = async ({);return Body as Readable;};++export const lambdaHeadCommand = async ({+ bucketName,+ key,+ region,+}: {+ bucketName: string;+ key: string;+ region: AwsRegion;+}): Promise<{+ LastModified?: Date | undefined;+ ContentLength?: number | undefined;+}> => {+ const head = await getS3Client(region, null).send(+ new HeadObjectCommand({+ Bucket: bucketName,+ Key: key,+ })+ );+ return head;+};