File tree 3 files changed +29
-3
lines changed
3 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -231,7 +231,10 @@ export default {
231
231
progress : { percentage : 100 , humanFileSize : file . humanSize , bytesUploaded : file . _File . size }
232
232
}
233
233
} ) ;
234
- if ( state . files . every ( f => f . uploaded ) ) commit ( 'STATE' , 'uploaded' , { root : true } ) ;
234
+ if ( state . files . every ( f => f . uploaded ) ) {
235
+ fetch ( state . uploadURI + '/' + state . sid + '?lock=yes' , { method : 'PATCH' } ) ;
236
+ commit ( 'STATE' , 'uploaded' , { root : true } ) ;
237
+ }
235
238
}
236
239
} ) . start ( ) ;
237
240
}
Original file line number Diff line number Diff line change @@ -132,6 +132,19 @@ module.exports = class DB {
132
132
await this . store . update ( `${ sid } ++${ key } ` , file ) ;
133
133
}
134
134
135
+ async lock ( sid ) {
136
+ const files = this . get ( sid ) ;
137
+ if ( ! files ) return ;
138
+ await Promise . all ( files . map ( async file => {
139
+ await this . updateMetadata ( sid , file . key , { buckedLocked : true } ) ;
140
+ } ) ) ;
141
+ }
142
+
143
+ isLocked ( sid ) {
144
+ const files = this . get ( sid ) ;
145
+ if ( ! files ) return false ;
146
+ return files . some ( file => file . metadata . buckedLocked ) ;
147
+ }
135
148
136
149
get ( sid ) {
137
150
return this . db [ sid ] ;
Original file line number Diff line number Diff line change @@ -332,11 +332,21 @@ 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 a file which upload completed already
340
350
if ( ! info . isPartial ) {
341
351
return res . status ( 400 ) . end ( 'Upload already completed' ) ;
342
352
}
You can’t perform that action at this time.
0 commit comments