Skip to content

Commit

Permalink
Merge pull request #39 from QuantStack/maxKeys
Browse files Browse the repository at this point in the history
Add limit to object listings in helping functions
  • Loading branch information
DenisaCG authored Jan 23, 2025
2 parents cfdcb8b + 7f7937d commit 6e07065
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions src/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,23 +376,21 @@ export const checkS3Object = async (
path?: string,
isDir?: boolean
): Promise<void> => {
// checking the existance of an S3 object
if (path) {
await s3Client.send(
new HeadObjectCommand({
Bucket: bucketName,
Key: PathExt.join(root, path) + (isDir === true ? '/' : '')
})
);
}
// checking if the root folder exists
else {
await s3Client.send(
new ListObjectsV2Command({
Bucket: bucketName,
Prefix: root + '/'
})
);
// checking the existance of an S3 object or if root folder exists
const prefix: string = path
? PathExt.join(root, path) + (isDir === true ? '/' : '')
: root + '/';
const { Contents } = await s3Client.send(
new ListObjectsV2Command({
Bucket: bucketName,
Prefix: prefix,
MaxKeys: 1
})
);
if (Contents) {
Promise.resolve();
} else {
Promise.reject();
}
};

Expand Down Expand Up @@ -696,7 +694,8 @@ export async function isDirectory(
const command = new ListObjectsV2Command({
Bucket: bucketName,
Prefix:
objectPath[objectPath.length - 1] === '/' ? objectPath : objectPath + '/'
objectPath[objectPath.length - 1] === '/' ? objectPath : objectPath + '/',
MaxKeys: 1
});

const { Contents } = await s3Client.send(command);
Expand Down

0 comments on commit 6e07065

Please sign in to comment.