Skip to content

🎥 Make videos programmatically with React

serialize props

Jonny Burger701e742bc7b6
diff --git a/packages/lambda/src/api/get-compositions-on-lambda.ts b/packages/lambda/src/api/get-compositions-on-lambda.ts
index 631ebce5ab..f5e8fb5577 100644
--- a/packages/lambda/src/api/get-compositions-on-lambda.ts
+++ b/packages/lambda/src/api/get-compositions-on-lambda.ts
@@ -4,7 +4,7 @@ import {VERSION} from 'remotion/version';
import type {AwsRegion} from '../client';
import {LambdaRoutines} from '../defaults';
import {callLambda} from '../shared/call-lambda';
-import {serializeInputProps} from '../shared/serialize-input-props';
+import {serializeInputProps} from '../shared/serialize-props';
export type GetCompositionsOnLambdaInput = {
chromiumOptions?: ChromiumOptions;
diff --git a/packages/lambda/src/api/make-lambda-payload.ts b/packages/lambda/src/api/make-lambda-payload.ts
index a4b845670c..4f0e9a7733 100644
--- a/packages/lambda/src/api/make-lambda-payload.ts
+++ b/packages/lambda/src/api/make-lambda-payload.ts
@@ -1,7 +1,7 @@
import {VERSION} from 'remotion/version';
import type {LambdaStartPayload, LambdaStatusPayload} from '../defaults';
import {LambdaRoutines} from '../defaults';
-import {serializeInputProps} from '../shared/serialize-input-props';
+import {serializeInputProps} from '../shared/serialize-props';
import {validateDownloadBehavior} from '../shared/validate-download-behavior';
import {validateFramesPerLambda} from '../shared/validate-frames-per-lambda';
import {validateLambdaCodec} from '../shared/validate-lambda-codec';
diff --git a/packages/lambda/src/api/render-still-on-lambda.ts b/packages/lambda/src/api/render-still-on-lambda.ts
index a0c2bbdbcf..8e0f9dcd92 100644
--- a/packages/lambda/src/api/render-still-on-lambda.ts
+++ b/packages/lambda/src/api/render-still-on-lambda.ts
@@ -10,7 +10,7 @@ import type {CostsInfo, OutNameInput, Privacy} from '../shared/constants';
import {DEFAULT_MAX_RETRIES, LambdaRoutines} from '../shared/constants';
import type {DownloadBehavior} from '../shared/content-disposition-header';
import {getCloudwatchStreamUrl} from '../shared/get-aws-urls';
-import {serializeInputProps} from '../shared/serialize-input-props';
+import {serializeInputProps} from '../shared/serialize-props';
export type RenderStillOnLambdaInput = {
region: AwsRegion;
diff --git a/packages/lambda/src/functions/compositions.ts b/packages/lambda/src/functions/compositions.ts
index b9262b4c5a..5208b67b2e 100644
--- a/packages/lambda/src/functions/compositions.ts
+++ b/packages/lambda/src/functions/compositions.ts
@@ -4,9 +4,9 @@ import {getOrCreateBucket} from '../api/get-or-create-bucket';
import type {LambdaPayload} from '../defaults';
import {LambdaRoutines} from '../defaults';
import {convertToServeUrl} from '../shared/convert-to-serve-url';
-import {deserializeInputProps} from '../shared/deserialize-input-props';
import {getBrowserInstance} from './helpers/get-browser-instance';
import {getCurrentRegionInFunction} from './helpers/get-current-region';
+import {deserializeInputProps} from '../shared/serialize-props';
type Options = {
expectedBucketOwner: string;
diff --git a/packages/lambda/src/functions/launch.ts b/packages/lambda/src/functions/launch.ts
index bb9420ebaa..04a972d32a 100644
--- a/packages/lambda/src/functions/launch.ts
+++ b/packages/lambda/src/functions/launch.ts
@@ -17,7 +17,6 @@ import {
renderMetadataKey,
rendersPrefix,
} from '../shared/constants';
-import {deserializeInputProps} from '../shared/deserialize-input-props';
import {DOCS_URL} from '../shared/docs-url';
import {invokeWebhook} from '../shared/invoke-webhook';
import {getServeUrlHash} from '../shared/make-s3-url';
@@ -45,6 +44,7 @@ import {
writeLambdaError,
} from './helpers/write-lambda-error';
import {writePostRenderData} from './helpers/write-post-render-data';
+import {deserializeInputProps} from '../shared/serialize-props';
type Options = {
expectedBucketOwner: string;
diff --git a/packages/lambda/src/functions/renderer.ts b/packages/lambda/src/functions/renderer.ts
index 75f2fa34f3..4a0859535f 100644
--- a/packages/lambda/src/functions/renderer.ts
+++ b/packages/lambda/src/functions/renderer.ts
@@ -13,7 +13,6 @@ import {
lambdaTimingsKey,
RENDERER_PATH_TOKEN,
} from '../shared/constants';
-import {deserializeInputProps} from '../shared/deserialize-input-props';
import type {
ChunkTimingData,
ObjectChunkTimingData,
@@ -26,6 +25,7 @@ import {
getTmpDirStateIfENoSp,
writeLambdaError,
} from './helpers/write-lambda-error';
+import {deserializeInputProps} from '../shared/serialize-props';
type Options = {
expectedBucketOwner: string;
diff --git a/packages/lambda/src/functions/still.ts b/packages/lambda/src/functions/still.ts
index f93976099d..9ce49c889a 100644
--- a/packages/lambda/src/functions/still.ts
+++ b/packages/lambda/src/functions/still.ts
@@ -19,7 +19,6 @@ import {
renderMetadataKey,
} from '../shared/constants';
import {convertToServeUrl} from '../shared/convert-to-serve-url';
-import {deserializeInputProps} from '../shared/deserialize-input-props';
import {getServeUrlHash} from '../shared/make-s3-url';
import {randomHash} from '../shared/random-hash';
import {validateDownloadBehavior} from '../shared/validate-download-behavior';
@@ -40,6 +39,7 @@ import {
getTmpDirStateIfENoSp,
writeLambdaError,
} from './helpers/write-lambda-error';
+import {deserializeInputProps} from '../shared/serialize-props';
type Options = {
expectedBucketOwner: string;
diff --git a/packages/lambda/src/shared/deserialize-input-props.ts b/packages/lambda/src/shared/deserialize-input-props.ts
deleted file mode 100644
index 06ce251ef4..0000000000
--- a/packages/lambda/src/shared/deserialize-input-props.ts
+++ /dev/null
@@ -1,41 +0,0 @@
-import type {AwsRegion} from '../client';
-import {lambdaReadFile} from '../functions/helpers/io';
-import type {SerializedInputProps} from './constants';
-import {inputPropsKey} from './constants';
-import {streamToString} from './stream-to-string';
-
-export const deserializeInputProps = async ({
- serialized,
- region,
- bucketName,
- expectedBucketOwner,
-}: {
- serialized: SerializedInputProps;
- region: AwsRegion;
- bucketName: string;
- expectedBucketOwner: string;
-}): Promise<Record<string, unknown>> => {
- if (serialized.type === 'payload') {
- return JSON.parse(serialized.payload as string);
- }
-
- try {
- const response = await lambdaReadFile({
- bucketName,
- expectedBucketOwner,
- key: inputPropsKey(serialized.hash),
- region,
- });
-
- const body = await streamToString(response);
- const payload = JSON.parse(body);
-
- return payload;
- } catch (err) {
- throw new Error(
- `Failed to parse input props that were serialized: ${
- (err as Error).stack
- }`
- );
- }
-};
diff --git a/packages/lambda/src/shared/serialize-input-props.ts b/packages/lambda/src/shared/serialize-props.ts
similarity index 64%
rename from packages/lambda/src/shared/serialize-input-props.ts
rename to packages/lambda/src/shared/serialize-props.ts
index 9a40c503e4..fe062ad8bf 100644
--- a/packages/lambda/src/shared/serialize-input-props.ts
+++ b/packages/lambda/src/shared/serialize-props.ts
@@ -1,12 +1,13 @@
import {getOrCreateBucket} from '../api/get-or-create-bucket';
import type {AwsRegion} from '../client';
-import {lambdaWriteFile} from '../functions/helpers/io';
+import {lambdaReadFile, lambdaWriteFile} from '../functions/helpers/io';
import type {SerializedInputProps} from './constants';
import {inputPropsKey} from './constants';
import {randomHash} from './random-hash';
+import {streamToString} from './stream-to-string';
export const serializeInputProps = async ({
- inputProps = {},
+ inputProps,
region,
type,
userSpecifiedBucketName,
@@ -65,3 +66,39 @@ export const serializeInputProps = async ({
);
}
};
+
+export const deserializeInputProps = async ({
+ serialized,
+ region,
+ bucketName,
+ expectedBucketOwner,
+}: {
+ serialized: SerializedInputProps;
+ region: AwsRegion;
+ bucketName: string;
+ expectedBucketOwner: string;
+}): Promise<Record<string, unknown>> => {
+ if (serialized.type === 'payload') {
+ return JSON.parse(serialized.payload as string);
+ }
+
+ try {
+ const response = await lambdaReadFile({
+ bucketName,
+ expectedBucketOwner,
+ key: inputPropsKey(serialized.hash),
+ region,
+ });
+
+ const body = await streamToString(response);
+ const payload = JSON.parse(body);
+
+ return payload;
+ } catch (err) {
+ throw new Error(
+ `Failed to parse input props that were serialized: ${
+ (err as Error).stack
+ }`
+ );
+ }
+};