|
7 | 7 | GetObjectCommand,
|
8 | 8 | PutObjectCommand,
|
9 | 9 | HeadObjectCommand,
|
10 |
| - HeadObjectCommandOutput, |
| 10 | + // HeadObjectCommandOutput, |
11 | 11 | S3Client
|
12 | 12 | } from '@aws-sdk/client-s3';
|
13 | 13 |
|
@@ -357,13 +357,49 @@ export const checkS3Object = async (
|
357 | 357 | bucketName: string,
|
358 | 358 | root: string,
|
359 | 359 | path?: string
|
360 |
| -): Promise<HeadObjectCommandOutput> => { |
361 |
| - return await s3Client.send( |
362 |
| - new HeadObjectCommand({ |
363 |
| - Bucket: bucketName, |
364 |
| - Key: path ? PathExt.join(root, path) : root + '/' // check whether we are looking at an object or the root |
365 |
| - }) |
366 |
| - ); |
| 360 | +): Promise<void> => { |
| 361 | + // checking the existance of an S3 object |
| 362 | + if (path) { |
| 363 | + try { |
| 364 | + await s3Client.send( |
| 365 | + new HeadObjectCommand({ |
| 366 | + Bucket: bucketName, |
| 367 | + Key: PathExt.join(root, path) |
| 368 | + }) |
| 369 | + ); |
| 370 | + } catch { |
| 371 | + Promise.reject(); |
| 372 | + } |
| 373 | + } else { |
| 374 | + // checking if the root folder exists |
| 375 | + const rootInfo = await s3Client.send( |
| 376 | + new ListObjectsV2Command({ |
| 377 | + Bucket: bucketName, |
| 378 | + Prefix: root + '/' |
| 379 | + }) |
| 380 | + ); |
| 381 | + |
| 382 | + if (rootInfo.Contents!.length > 0) { |
| 383 | + Promise.resolve(); |
| 384 | + } else { |
| 385 | + Promise.reject(); |
| 386 | + } |
| 387 | + } |
| 388 | + // try { |
| 389 | + // await s3Client.send( |
| 390 | + // new HeadObjectCommand({ |
| 391 | + // Bucket: bucketName, |
| 392 | + // Key: path ? PathExt.join(root, path) : root + '/' // check whether we are looking at an object or the root |
| 393 | + // }) |
| 394 | + // ); |
| 395 | + // } catch (error) { |
| 396 | + // await s3Client.send( |
| 397 | + // new HeadObjectCommand({ |
| 398 | + // Bucket: bucketName, |
| 399 | + // Key: path ? PathExt.join(root, path) : root + '/.emptyFolderPlaceholder' // check whether we are looking at an object or the root |
| 400 | + // }) |
| 401 | + // ); |
| 402 | + // } |
367 | 403 | };
|
368 | 404 |
|
369 | 405 | /**
|
@@ -700,7 +736,6 @@ namespace Private {
|
700 | 736 | Key: PathExt.join(newPath, remainingFilePath)
|
701 | 737 | })
|
702 | 738 | );
|
703 |
| - console.log('copy: ', PathExt.join(newPath, remainingFilePath)); |
704 | 739 | }
|
705 | 740 |
|
706 | 741 | /**
|
|
0 commit comments