@@ -332,11 +332,25 @@ app.use(`${ config.uploadAppPath }files`,
332
332
333
333
if ( req . method === 'GET' ) return res . status ( 405 ) . end ( ) ;
334
334
335
- // Restrict upload to a file which upload completed already
335
+ // Lock bucket by PATCH /files/:sid?lock=yes
336
+ const fid = req . path . substring ( 1 ) ;
337
+ if ( ! fid . includes ( '++' ) && req . method === 'PATCH' && req . query . lock ) {
338
+ await db . lock ( fid ) ;
339
+ return res . status ( 204 ) . end ( 'Bucket locked' ) ;
340
+ }
341
+
336
342
if ( [ 'POST' , 'PATCH' ] . includes ( req . method ) ) {
343
+ // Restrict upload to the bucket if it is locked
344
+ if ( ! fid . includes ( '++' ) && db . isLocked ( fid ) ) {
345
+ return res . status ( 400 ) . end ( 'Bucket locked' ) ;
346
+ }
337
347
try {
338
- const fid = req . url . substring ( 1 ) ;
339
348
const info = await store . info ( fid ) ;
349
+ // Restrict upload to the bucket if it is locked
350
+ if ( info . metadata . locked ) {
351
+ return res . status ( 400 ) . end ( 'Bucket locked' ) ;
352
+ }
353
+ // Restrict upload to a file which upload completed already
340
354
if ( ! info . isPartial ) {
341
355
return res . status ( 400 ) . end ( 'Upload already completed' ) ;
342
356
}
@@ -363,6 +377,11 @@ app.use(`${ config.uploadAppPath }files`,
363
377
const uploadLength = req . get ( 'Upload-Length' ) ;
364
378
assert ( uploadLength , 'missing Upload-Length header' ) ;
365
379
380
+ // Restrict creating new files for locked buckets
381
+ if ( db . isLocked ( meta . sid ) ) {
382
+ return res . status ( 400 ) . end ( 'Bucket locked' ) ;
383
+ }
384
+
366
385
meta . uploadLength = uploadLength ;
367
386
meta . key = uuid ( ) ;
368
387
meta . createdAt = Date . now ( ) . toString ( ) ;
0 commit comments