removing some extra .promise calls.
This commit is contained in:
parent
bb5361135c
commit
cd2286e8cb
|
@ -138,30 +138,25 @@ export async function createBucketIfNotExists(
|
||||||
): Promise<{ created: boolean; exists: boolean }> {
|
): Promise<{ created: boolean; exists: boolean }> {
|
||||||
bucketName = sanitizeBucket(bucketName)
|
bucketName = sanitizeBucket(bucketName)
|
||||||
try {
|
try {
|
||||||
await // The `.promise()` call might be on an JS SDK v2 client API.
|
await client.headBucket({
|
||||||
// If yes, please remove .promise(). If not, remove this comment.
|
Bucket: bucketName,
|
||||||
client
|
})
|
||||||
.headBucket({
|
|
||||||
Bucket: bucketName,
|
|
||||||
})
|
|
||||||
.promise()
|
|
||||||
return { created: false, exists: true }
|
return { created: false, exists: true }
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
const promises: any = STATE.bucketCreationPromises
|
const statusCode = err.statusCode || err.$response?.statusCode
|
||||||
const doesntExist = err.statusCode === 404,
|
const promises: Record<string, Promise<any> | undefined> =
|
||||||
noAccess = err.statusCode === 403
|
STATE.bucketCreationPromises
|
||||||
|
const doesntExist = statusCode === 404,
|
||||||
|
noAccess = statusCode === 403
|
||||||
if (promises[bucketName]) {
|
if (promises[bucketName]) {
|
||||||
await promises[bucketName]
|
await promises[bucketName]
|
||||||
return { created: false, exists: true }
|
return { created: false, exists: true }
|
||||||
} else if (doesntExist || noAccess) {
|
} else if (doesntExist || noAccess) {
|
||||||
if (doesntExist) {
|
if (doesntExist) {
|
||||||
promises[bucketName] = // The `.promise()` call might be on an JS SDK v2 client API.
|
promises[bucketName] = client.createBucket({
|
||||||
// If yes, please remove .promise(). If not, remove this comment.
|
Bucket: bucketName,
|
||||||
client
|
})
|
||||||
.createBucket({
|
|
||||||
Bucket: bucketName,
|
|
||||||
})
|
|
||||||
.promise()
|
|
||||||
await promises[bucketName]
|
await promises[bucketName]
|
||||||
delete promises[bucketName]
|
delete promises[bucketName]
|
||||||
return { created: true, exists: false }
|
return { created: true, exists: false }
|
||||||
|
@ -474,10 +469,7 @@ export async function deleteFolder(
|
||||||
Prefix: folder,
|
Prefix: folder,
|
||||||
}
|
}
|
||||||
|
|
||||||
const existingObjectsResponse =
|
const existingObjectsResponse = await client.listObjects(listParams)
|
||||||
await // The `.promise()` call might be on an JS SDK v2 client API.
|
|
||||||
// If yes, please remove .promise(). If not, remove this comment.
|
|
||||||
client.listObjects(listParams)
|
|
||||||
if (existingObjectsResponse.Contents?.length === 0) {
|
if (existingObjectsResponse.Contents?.length === 0) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue