🌳
pt0/bktF/deployF/listObjectsByPrefixF.mts
1import { ListObjectsV2Command } from '@aws-sdk/client-s3'
4export const listObjectsByPrefix = async ({bucket_name, prefix, maxKeys = 1000}: {
5 bucket_name: string, prefix: string, maxKeys?: number
6}) => {
7 const s3 = getS3Client({bucket_name})
8 const contentsA: {Key?: string, LastModified?: Date, Size?: number}[] = []
9 let continuationToken: string | undefined
10 do {
11 const resp = await s3.send(new ListObjectsV2Command({
12 Bucket: bucket_name, Prefix: prefix, MaxKeys: maxKeys, ContinuationToken: continuationToken,
13 }))
14 for (const obj of resp.Contents ?? []) contentsA.push(obj as any)
15 continuationToken = resp.IsTruncated ? resp.NextContinuationToken : undefined
16 } while (continuationToken)
17 return contentsA