@aws-amplify/storage
Version:
Storage category of aws-amplify
49 lines (46 loc) • 1.87 kB
JavaScript
import { StorageAction } from '@aws-amplify/core/internals/utils';
import './client/s3data/base.mjs';
import './client/s3data/getObject.mjs';
import { listObjectsV2 } from './client/s3data/listObjectsV2.mjs';
import './client/s3data/putObject.mjs';
import './client/s3data/createMultipartUpload.mjs';
import './client/s3data/uploadPart.mjs';
import './client/s3data/completeMultipartUpload.mjs';
import './client/s3data/listParts.mjs';
import './client/s3data/abortMultipartUpload.mjs';
import './client/s3data/copyObject.mjs';
import './client/s3data/headObject.mjs';
import './client/s3data/deleteObject.mjs';
import './client/s3data/deleteObjects.mjs';
import { getStorageUserAgentValue } from './userAgent.mjs';
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/**
* Determines if a given S3 key represents a folder by checking if objects exist with that prefix.
*
* @param params - Configuration object for the folder check
* @returns Promise that resolves to true if the key represents a folder, false otherwise
*/
const isPathFolder = async (params) => {
const { s3Config, bucket, key, expectedBucketOwner } = params;
try {
const prefix = key.endsWith('/') ? key : `${key}/`;
const result = await listObjectsV2({
...s3Config,
userAgentValue: getStorageUserAgentValue(StorageAction.Remove),
}, {
Bucket: bucket,
Prefix: prefix,
MaxKeys: 1,
ExpectedBucketOwner: expectedBucketOwner,
});
const isFolder = !!(result.Contents && result.Contents.length > 0) ||
!!(result.CommonPrefixes && result.CommonPrefixes.length > 0);
return isFolder;
}
catch (error) {
return false;
}
};
export { isPathFolder };
//# sourceMappingURL=isPathFolder.mjs.map