Skip to content

Commit 6c58891

Browse files
committed
fix root formatting error
1 parent 846580a commit 6c58891

File tree

1 file changed

+44
-9
lines changed

1 file changed

+44
-9
lines changed

src/s3.ts

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
GetObjectCommand,
88
PutObjectCommand,
99
HeadObjectCommand,
10-
HeadObjectCommandOutput,
10+
// HeadObjectCommandOutput,
1111
S3Client
1212
} from '@aws-sdk/client-s3';
1313

@@ -357,13 +357,49 @@ export const checkS3Object = async (
357357
bucketName: string,
358358
root: string,
359359
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+
// }
367403
};
368404

369405
/**
@@ -700,7 +736,6 @@ namespace Private {
700736
Key: PathExt.join(newPath, remainingFilePath)
701737
})
702738
);
703-
console.log('copy: ', PathExt.join(newPath, remainingFilePath));
704739
}
705740

706741
/**

0 commit comments

Comments
 (0)