@@ -550,21 +550,51 @@ function listPrefixReqV2 (mac, config, bucket, options, callbackFunc) {
550
550
551
551
// 批量文件管理请求,支持stat,chgm,chtype,delete,copy,move
552
552
BucketManager . prototype . batch = function ( operations , callbackFunc ) {
553
- var scheme = this . config . useHttpsDomain ? 'https://' : 'http://' ;
554
- var requestURI = scheme + conf . RS_HOST + '/batch' ;
555
- var reqParams = {
553
+ if ( ! operations . length ) {
554
+ callbackFunc ( new Error ( 'Empty operations' ) , null , null )
555
+ }
556
+
557
+ let bucket ;
558
+ for ( const op of operations ) {
559
+ const [ , , entry ] = op . split ( '/' ) ;
560
+ if ( ! entry ) {
561
+ continue ;
562
+ }
563
+ [ bucket ] = util . decodedEntry ( entry ) ;
564
+ if ( bucket ) {
565
+ break ;
566
+ }
567
+ }
568
+ if ( ! bucket ) {
569
+ callbackFunc ( new Error ( 'Empty bucket' ) ) ;
570
+ return ;
571
+ }
572
+
573
+ util . prepareZone ( this , this . mac . accessKey , bucket , function ( err , ctx ) {
574
+ if ( err ) {
575
+ callbackFunc ( err , null , null ) ;
576
+ return ;
577
+ }
578
+ batchReq ( ctx . mac , ctx . config , operations , callbackFunc ) ;
579
+ } ) ;
580
+ } ;
581
+
582
+ function batchReq ( mac , config , operations , callbackFunc ) {
583
+ const scheme = config . useHttpsDomain ? 'https://' : 'http://' ;
584
+ const requestURI = scheme + config . zone . rsHost + '/batch' ;
585
+ const reqParams = {
556
586
op : operations
557
587
} ;
558
- var reqBody = querystring . stringify ( reqParams ) ;
588
+ const reqBody = querystring . stringify ( reqParams ) ;
559
589
rpc . postWithOptions (
560
590
requestURI ,
561
591
reqBody ,
562
592
{
563
- mac : this . mac
593
+ mac : mac
564
594
} ,
565
595
callbackFunc
566
596
) ;
567
- } ;
597
+ }
568
598
569
599
// 批量操作支持的指令构造器
570
600
exports . statOp = function ( bucket , key ) {
@@ -1309,17 +1339,28 @@ BucketManager.prototype.listBucketDomains = function (bucket, callbackFunc) {
1309
1339
1310
1340
// 解冻归档存储文件
1311
1341
BucketManager . prototype . restoreAr = function ( entry , freezeAfterDays , callbackFunc ) {
1312
- var scheme = this . config . useHttpsDomain ? 'https://' : 'http://' ;
1313
- var requestURI = scheme + conf . RS_HOST + '/restoreAr/' + util . urlsafeBase64Encode ( entry ) + '/freezeAfterDays/' + freezeAfterDays ;
1342
+ const [ bucket ] = entry . split ( ':' ) ;
1343
+ util . prepareZone ( this , this . mac . accessKey , bucket , function ( err , ctx ) {
1344
+ if ( err ) {
1345
+ callbackFunc ( err , null , null ) ;
1346
+ return ;
1347
+ }
1348
+ restoreArReq ( ctx . mac , ctx . config , entry , freezeAfterDays , callbackFunc ) ;
1349
+ } ) ;
1350
+ } ;
1351
+
1352
+ function restoreArReq ( mac , config , entry , freezeAfterDays , callbackFunc ) {
1353
+ const scheme = config . useHttpsDomain ? 'https://' : 'http://' ;
1354
+ const requestURI = scheme + config . zone . rsHost + '/restoreAr/' + util . urlsafeBase64Encode ( entry ) + '/freezeAfterDays/' + freezeAfterDays ;
1314
1355
rpc . postWithOptions (
1315
1356
requestURI ,
1316
1357
null ,
1317
1358
{
1318
- mac : this . mac
1359
+ mac : mac
1319
1360
} ,
1320
1361
callbackFunc
1321
1362
) ;
1322
- } ;
1363
+ }
1323
1364
1324
1365
// 上传策略
1325
1366
// @link https://developer.qiniu.com/kodo/manual/1206/put-policy
0 commit comments