File tree Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -97,6 +97,7 @@ type StorageConfigType = {
97
97
responseSMaxAge : number
98
98
anonKeyAsync : Promise < string >
99
99
serviceKeyAsync : Promise < string >
100
+ emptyBucketMax : number
100
101
storageBackendType : StorageBackendType
101
102
tenantId : string
102
103
requestUrlLengthLimit : number
@@ -311,6 +312,10 @@ export function getConfig(options?: { reload?: boolean }): StorageConfigType {
311
312
) ,
312
313
// Storage
313
314
storageBackendType : getOptionalConfigFromEnv ( 'STORAGE_BACKEND' ) as StorageBackendType ,
315
+ emptyBucketMax : parseInt (
316
+ getOptionalConfigFromEnv ( 'STORAGE_EMPTY_BUCKET_MAX' ) || '200000' ,
317
+ 10
318
+ ) ,
314
319
315
320
// Storage - File
316
321
storageFilePath : getOptionalConfigFromEnv (
Original file line number Diff line number Diff line change @@ -49,6 +49,14 @@ export const ERRORS = {
49
49
message : `The bucket you tried to delete is not empty` ,
50
50
originalError : e ,
51
51
} ) ,
52
+ UnableToEmptyBucket : ( bucket : string , e ?: Error ) =>
53
+ new StorageBackendError ( {
54
+ code : ErrorCode . InvalidRequest ,
55
+ resource : bucket ,
56
+ httpStatusCode : 409 ,
57
+ message : `Unable to empty the bucket because it contains too many objects` ,
58
+ originalError : e ,
59
+ } ) ,
52
60
NoSuchBucket : ( bucket : string , e ?: Error ) =>
53
61
new StorageBackendError ( {
54
62
code : ErrorCode . NoSuchBucket ,
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ import { ObjectStorage } from './object'
8
8
import { InfoRenderer } from '@storage/renderer/info'
9
9
import { ObjectAdminDeleteBatch } from './events'
10
10
11
- const { requestUrlLengthLimit } = getConfig ( )
11
+ const { requestUrlLengthLimit, emptyBucketMax } = getConfig ( )
12
12
13
13
/**
14
14
* Storage
@@ -182,6 +182,11 @@ export class Storage {
182
182
async emptyBucket ( bucketId : string ) {
183
183
await this . findBucket ( bucketId , 'name' )
184
184
185
+ const count = await this . countObjects ( bucketId )
186
+ if ( count > emptyBucketMax ) {
187
+ throw ERRORS . UnableToEmptyBucket ( bucketId )
188
+ }
189
+
185
190
while ( true ) {
186
191
const objects = await this . db . listObjects (
187
192
bucketId ,
You can’t perform that action at this time.
0 commit comments