update bucketcreate return
This commit is contained in:
parent
8534cb8ca9
commit
b7cda9bb83
|
@ -129,7 +129,7 @@ export function ObjectStore(
|
||||||
export async function createBucketIfNotExists(
|
export async function createBucketIfNotExists(
|
||||||
client: any,
|
client: any,
|
||||||
bucketName: string
|
bucketName: string
|
||||||
): Promise<boolean> {
|
): Promise<{ created: boolean; exists: boolean }> {
|
||||||
bucketName = sanitizeBucket(bucketName)
|
bucketName = sanitizeBucket(bucketName)
|
||||||
try {
|
try {
|
||||||
await client
|
await client
|
||||||
|
@ -137,14 +137,14 @@ export async function createBucketIfNotExists(
|
||||||
Bucket: bucketName,
|
Bucket: bucketName,
|
||||||
})
|
})
|
||||||
.promise()
|
.promise()
|
||||||
return false
|
return { created: false, exists: true }
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
const promises: any = STATE.bucketCreationPromises
|
const promises: any = STATE.bucketCreationPromises
|
||||||
const doesntExist = err.statusCode === 404,
|
const doesntExist = err.statusCode === 404,
|
||||||
noAccess = err.statusCode === 403
|
noAccess = err.statusCode === 403
|
||||||
if (promises[bucketName]) {
|
if (promises[bucketName]) {
|
||||||
await promises[bucketName]
|
await promises[bucketName]
|
||||||
return false
|
return { created: false, exists: true }
|
||||||
} else if (doesntExist || noAccess) {
|
} else if (doesntExist || noAccess) {
|
||||||
if (doesntExist) {
|
if (doesntExist) {
|
||||||
promises[bucketName] = client
|
promises[bucketName] = client
|
||||||
|
@ -154,7 +154,7 @@ export async function createBucketIfNotExists(
|
||||||
.promise()
|
.promise()
|
||||||
await promises[bucketName]
|
await promises[bucketName]
|
||||||
delete promises[bucketName]
|
delete promises[bucketName]
|
||||||
return true
|
return { created: true, exists: false }
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Access denied to object store bucket.")
|
throw new Error("Access denied to object store bucket.")
|
||||||
}
|
}
|
||||||
|
@ -183,7 +183,7 @@ export async function upload({
|
||||||
const objectStore = ObjectStore(bucketName)
|
const objectStore = ObjectStore(bucketName)
|
||||||
const bucketCreated = await createBucketIfNotExists(objectStore, bucketName)
|
const bucketCreated = await createBucketIfNotExists(objectStore, bucketName)
|
||||||
|
|
||||||
if (addTTL && bucketCreated) {
|
if (addTTL && bucketCreated.created) {
|
||||||
let ttlConfig = bucketTTLConfig(bucketName, 1)
|
let ttlConfig = bucketTTLConfig(bucketName, 1)
|
||||||
await objectStore.putBucketLifecycleConfiguration(ttlConfig).promise()
|
await objectStore.putBucketLifecycleConfiguration(ttlConfig).promise()
|
||||||
}
|
}
|
||||||
|
@ -229,7 +229,7 @@ export async function streamUpload({
|
||||||
const objectStore = ObjectStore(bucketName)
|
const objectStore = ObjectStore(bucketName)
|
||||||
const bucketCreated = await createBucketIfNotExists(objectStore, bucketName)
|
const bucketCreated = await createBucketIfNotExists(objectStore, bucketName)
|
||||||
|
|
||||||
if (addTTL && bucketCreated) {
|
if (addTTL && bucketCreated.created) {
|
||||||
let ttlConfig = bucketTTLConfig(bucketName, 1)
|
let ttlConfig = bucketTTLConfig(bucketName, 1)
|
||||||
await objectStore.putBucketLifecycleConfiguration(ttlConfig).promise()
|
await objectStore.putBucketLifecycleConfiguration(ttlConfig).promise()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue