Skip to content

🎥 Make videos programmatically with React

duplicate code for now

Jonny Burgerceca47cb659a
diff --git a/packages/core/src/input-props-serialization.ts b/packages/core/src/input-props-serialization.ts
index b4ba9e39c7..cd67a61023 100644
--- a/packages/core/src/input-props-serialization.ts
+++ b/packages/core/src/input-props-serialization.ts
@@ -1,3 +1,5 @@
+// Must keep this file in sync with the one in packages/lambda/src/shared/serialize-props.ts!
+
import {staticFile} from './static-file.js';
export type SerializedJSONWithCustomFields = {
diff --git a/packages/lambda/src/shared/compress-props.ts b/packages/lambda/src/shared/compress-props.ts
index 845cd34224..317ea3bd8e 100644
--- a/packages/lambda/src/shared/compress-props.ts
+++ b/packages/lambda/src/shared/compress-props.ts
@@ -1,4 +1,3 @@
-import {Internals} from 'remotion';
import {getOrCreateBucket} from '../api/get-or-create-bucket';
import type {AwsRegion} from '../client';
import {lambdaReadFile, lambdaWriteFile} from '../functions/helpers/io';
@@ -6,6 +5,7 @@ import type {SerializedInputProps} from './constants';
import {inputPropsKey, resolvedPropsKey} from './constants';
import {randomHash} from './random-hash';
import {streamToString} from './stream-to-string';
+import {serializeJSONWithDate} from './serialize-props';
type PropsType = 'input-props' | 'resolved-props';
@@ -14,7 +14,7 @@ export const serializeOrThrow = (
propsType: PropsType
) => {
try {
- const payload = Internals.serializeJSONWithDate({
+ const payload = serializeJSONWithDate({
indent: undefined,
staticBase: null,
data: inputProps,
diff --git a/packages/lambda/src/shared/serialize-props.ts b/packages/lambda/src/shared/serialize-props.ts
new file mode 100644
index 0000000000..c7240f5247
--- /dev/null
+++ b/packages/lambda/src/shared/serialize-props.ts
@@ -0,0 +1,62 @@
+// Must keep this file in sync with the one in packages/core/src/input-props-serialization.ts!
+
+type SerializedJSONWithCustomFields = {
+ serializedString: string;
+ customDateUsed: boolean;
+ customFileUsed: boolean;
+ mapUsed: boolean;
+ setUsed: boolean;
+};
+
+const DATE_TOKEN = 'remotion-date:';
+export const FILE_TOKEN = 'remotion-file:';
+
+export const serializeJSONWithDate = ({
+ data,
+ indent,
+ staticBase,
+}: {
+ data: Record<string, unknown>;
+ indent: number | undefined;
+ staticBase: string | null;
+}): SerializedJSONWithCustomFields => {
+ let customDateUsed = false;
+ let customFileUsed = false;
+ let mapUsed = false;
+ let setUsed = false;
+
+ const serializedString = JSON.stringify(
+ data,
+ function (key, value) {
+ const item = (this as Record<string, unknown>)[key];
+ if (item instanceof Date) {
+ customDateUsed = true;
+ return `${DATE_TOKEN}${item.toISOString()}`;
+ }
+
+ if (item instanceof Map) {
+ mapUsed = true;
+ return value;
+ }
+
+ if (item instanceof Set) {
+ setUsed = true;
+ return value;
+ }
+
+ if (
+ typeof item === 'string' &&
+ staticBase !== null &&
+ item.startsWith(staticBase)
+ ) {
+ customFileUsed = true;
+ return `${FILE_TOKEN}${item.replace(staticBase + '/', '')}`;
+ }
+
+ return value;
+ },
+ indent
+ );
+
+ return {serializedString, customDateUsed, customFileUsed, mapUsed, setUsed};
+};