@@ -550,21 +550,51 @@ function listPrefixReqV2 (mac, config, bucket, options, callbackFunc) {
550550
551551// 批量文件管理请求,支持stat,chgm,chtype,delete,copy,move
552552BucketManager . 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 = {
556586 op : operations
557587 } ;
558- var reqBody = querystring . stringify ( reqParams ) ;
588+ const reqBody = querystring . stringify ( reqParams ) ;
559589 rpc . postWithOptions (
560590 requestURI ,
561591 reqBody ,
562592 {
563- mac : this . mac
593+ mac : mac
564594 } ,
565595 callbackFunc
566596 ) ;
567- } ;
597+ }
568598
569599// 批量操作支持的指令构造器
570600exports . statOp = function ( bucket , key ) {
@@ -1309,17 +1339,28 @@ BucketManager.prototype.listBucketDomains = function (bucket, callbackFunc) {
13091339
13101340// 解冻归档存储文件
13111341BucketManager . 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 ;
13141355 rpc . postWithOptions (
13151356 requestURI ,
13161357 null ,
13171358 {
1318- mac : this . mac
1359+ mac : mac
13191360 } ,
13201361 callbackFunc
13211362 ) ;
1322- } ;
1363+ }
13231364
13241365// 上传策略
13251366// @link https://developer.qiniu.com/kodo/manual/1206/put-policy
0 commit comments