Skip to content

🎥 Make videos programmatically with React

pagination

Jonny Burger9bc8d362ecae
diff --git a/packages/lambda/src/functions/helpers/io.ts b/packages/lambda/src/functions/helpers/io.ts
index 55c158c3fb..c573c3b9de 100644
--- a/packages/lambda/src/functions/helpers/io.ts
+++ b/packages/lambda/src/functions/helpers/io.ts
@@ -14,21 +14,36 @@ export const lambdaLs = async ({
prefix,
region,
expectedBucketOwner,
+ continuationToken,
}: {
bucketName: string;
prefix: string;
region: AwsRegion;
expectedBucketOwner: string | null;
+ continuationToken?: string;
}): Promise<_Object[]> => {
try {
- // TODO: Should paginate with list.ContinuationToken
const list = await getS3Client(region).send(
new ListObjectsV2Command({
Bucket: bucketName,
Prefix: prefix,
ExpectedBucketOwner: expectedBucketOwner ?? undefined,
+ ContinuationToken: continuationToken,
})
);
+ if (list.NextContinuationToken) {
+ return [
+ ...(list.Contents ?? []),
+ ...(await lambdaLs({
+ bucketName,
+ prefix,
+ expectedBucketOwner,
+ region,
+ continuationToken: list.NextContinuationToken,
+ })),
+ ];
+ }
+
return list.Contents ?? [];
} catch (err) {
if (!expectedBucketOwner) {