File tree Expand file tree Collapse file tree 1 file changed +17
-18
lines changed Expand file tree Collapse file tree 1 file changed +17
-18
lines changed Original file line number Diff line number Diff line change @@ -376,23 +376,21 @@ export const checkS3Object = async (
376
376
path ?: string ,
377
377
isDir ?: boolean
378
378
) : Promise < void > => {
379
- // checking the existance of an S3 object
380
- if ( path ) {
381
- await s3Client . send (
382
- new HeadObjectCommand ( {
383
- Bucket : bucketName ,
384
- Key : PathExt . join ( root , path ) + ( isDir === true ? '/' : '' )
385
- } )
386
- ) ;
387
- }
388
- // checking if the root folder exists
389
- else {
390
- await s3Client . send (
391
- new ListObjectsV2Command ( {
392
- Bucket : bucketName ,
393
- Prefix : root + '/'
394
- } )
395
- ) ;
379
+ // checking the existance of an S3 object or if root folder exists
380
+ const prefix : string = path
381
+ ? PathExt . join ( root , path ) + ( isDir === true ? '/' : '' )
382
+ : root + '/' ;
383
+ const { Contents } = await s3Client . send (
384
+ new ListObjectsV2Command ( {
385
+ Bucket : bucketName ,
386
+ Prefix : prefix ,
387
+ MaxKeys : 1
388
+ } )
389
+ ) ;
390
+ if ( Contents ) {
391
+ Promise . resolve ( ) ;
392
+ } else {
393
+ Promise . reject ( ) ;
396
394
}
397
395
} ;
398
396
@@ -696,7 +694,8 @@ export async function isDirectory(
696
694
const command = new ListObjectsV2Command ( {
697
695
Bucket : bucketName ,
698
696
Prefix :
699
- objectPath [ objectPath . length - 1 ] === '/' ? objectPath : objectPath + '/'
697
+ objectPath [ objectPath . length - 1 ] === '/' ? objectPath : objectPath + '/' ,
698
+ MaxKeys : 1
700
699
} ) ;
701
700
702
701
const { Contents } = await s3Client . send ( command ) ;
You can’t perform that action at this time.
0 commit comments