Skip to content

🎥 Make videos programmatically with React

fix still rendering on python

Jonny Burger8998ce85b254
diff --git a/packages/lambda/src/functions/index.ts b/packages/lambda/src/functions/index.ts
index 581bac8c32..2b2b22b6ce 100644
--- a/packages/lambda/src/functions/index.ts
+++ b/packages/lambda/src/functions/index.ts
@@ -34,7 +34,7 @@ const innerHandler = async ({
}: {
params: LambdaPayload;
responseWriter: ResponseStreamWriter;
- onStream: OnStream;
+ onStream: OnStream | undefined;
context: RequestContext;
}): Promise<void> => {
setCurrentRequestId(context.awsRequestId);
@@ -71,18 +71,26 @@ const innerHandler = async ({
params.logLevel,
);
- onStream({
- type: 'render-id-determined',
- payload: {renderId},
- });
+ if (onStream) {
+ onStream({
+ type: 'render-id-determined',
+ payload: {renderId},
+ });
+ }
- await stillHandler({
+ const res = await stillHandler({
expectedBucketOwner: currentUserId,
params,
renderId,
onStream,
});
+ // Response is only coming in if the still function was invoked without streaming.
+ // e.g. Python SDK.
+ if (res) {
+ await responseWriter.write(Buffer.from(JSON.stringify(res)));
+ }
+
await responseWriter.end();
return;
diff --git a/packages/lambda/src/functions/still.ts b/packages/lambda/src/functions/still.ts
index 4af452bfdc..84eae40064 100644
--- a/packages/lambda/src/functions/still.ts
+++ b/packages/lambda/src/functions/still.ts
@@ -47,7 +47,7 @@ type Options = {
params: LambdaPayload;
renderId: string;
expectedBucketOwner: string;
- onStream: OnStream;
+ onStream: OnStream | undefined;
};
const innerStillHandler = async ({
@@ -274,19 +274,25 @@ const innerStillHandler = async ({
customCredentials,
);
- onStream({
- type: 'still-rendered',
- payload: {
- type: 'success' as const,
- output: url,
- size,
- sizeInBytes: size,
- bucketName,
- estimatedPrice: formatCostsInfo(estimatedPrice),
- renderId,
- outKey,
- },
- });
+ const payload: RenderStillLambdaResponsePayload = {
+ type: 'success' as const,
+ output: url,
+ size,
+ sizeInBytes: size,
+ bucketName,
+ estimatedPrice: formatCostsInfo(estimatedPrice),
+ renderId,
+ outKey,
+ };
+
+ if (onStream) {
+ onStream({
+ type: 'still-rendered',
+ payload,
+ });
+ } else {
+ return payload;
+ }
};
export type RenderStillLambdaResponsePayload = {
@@ -300,7 +306,9 @@ export type RenderStillLambdaResponsePayload = {
renderId: string;
};
-export const stillHandler = async (options: Options): Promise<void> => {
+export const stillHandler = async (
+ options: Options,
+): Promise<RenderStillLambdaResponsePayload | null> => {
const {params} = options;
if (params.type !== LambdaRoutines.still) {
@@ -308,7 +316,8 @@ export const stillHandler = async (options: Options): Promise<void> => {
}
try {
- return await innerStillHandler(options);
+ const res = await innerStillHandler(options);
+ return res ?? null;
} catch (err) {
// If this error is encountered, we can just retry as it
// is a very rare error to occur