@@ -11,26 +11,42 @@ function OperationManager (mac, config) {
1111 this . config = config || new conf . Config ( ) ;
1212}
1313
14- // 发送持久化数据处理请求
15- // @param bucket - 空间名称
16- // @param key - 文件名称
17- // @param fops - 处理指令集合
18- // @param pipeline - 处理队列名称
19- // @param options - 可选参数
20- // notifyURL 回调业务服务器,通知处理结果
21- // force 结果是否强制覆盖已有的同名文件
22- // @param callbackFunc(err, respBody, respInfo) - 回调函数
23- OperationManager . prototype . pfop = function ( bucket , key , fops , pipeline ,
24- options , callbackFunc ) {
14+ /**
15+ * @typedef {function(Error, any, IncomingMessage) } OperationCallback
16+ */
17+
18+ /**
19+ * @param {string } bucket 空间名称
20+ * @param {string } key 文件名称
21+ * @param {string[] } fops 处理指令
22+ * @param {string } pipeline 队列名称
23+ * @param {object } options 可选参数
24+ * @param {string } [options.notifyURL] 回调业务服务器,通知处理结果
25+ * @param {boolean } [options.force] 是否强制覆盖已有的同名文件
26+ * @param {string } [options.type] 为 `1` 时,开启闲时任务
27+ * @param {OperationCallback } callbackFunc 回调函数
28+ */
29+ OperationManager . prototype . pfop = function (
30+ bucket ,
31+ key ,
32+ fops ,
33+ pipeline ,
34+ options ,
35+ callbackFunc
36+ ) {
2537 options = options || { } ;
2638 // 必须参数
27- var reqParams = {
39+ const reqParams = {
2840 bucket : bucket ,
2941 key : key ,
30- pipeline : pipeline ,
3142 fops : fops . join ( ';' )
3243 } ;
3344
45+ // pipeline
46+ if ( ! pipeline ) {
47+ delete reqParams . pipeline ;
48+ }
49+
3450 // notifyURL
3551 if ( options . notifyURL ) {
3652 reqParams . notifyURL = options . notifyURL ;
@@ -41,6 +57,11 @@ OperationManager.prototype.pfop = function (bucket, key, fops, pipeline,
4157 reqParams . force = 1 ;
4258 }
4359
60+ const persistentType = parseInt ( options . type , 10 ) ;
61+ if ( ! isNaN ( persistentType ) ) {
62+ reqParams . type = options . type ;
63+ }
64+
4465 util . prepareZone ( this , this . mac . accessKey , bucket , function ( err , ctx ) {
4566 if ( err ) {
4667 callbackFunc ( err , null , null ) ;
@@ -51,27 +72,32 @@ OperationManager.prototype.pfop = function (bucket, key, fops, pipeline,
5172} ;
5273
5374function pfopReq ( mac , config , reqParams , callbackFunc ) {
54- var scheme = config . useHttpsDomain ? 'https://' : 'http://' ;
55- var requestURI = scheme + config . zone . apiHost + '/pfop/' ;
56- var reqBody = querystring . stringify ( reqParams ) ;
57- var auth = util . generateAccessToken ( mac , requestURI , reqBody ) ;
75+ const scheme = config . useHttpsDomain ? 'https://' : 'http://' ;
76+ const requestURI = scheme + config . zone . apiHost + '/pfop/' ;
77+ const reqBody = querystring . stringify ( reqParams ) ;
78+ const auth = util . generateAccessToken ( mac , requestURI , reqBody ) ;
5879 rpc . postWithForm ( requestURI , reqBody , auth , callbackFunc ) ;
5980}
6081
61- // 查询持久化数据处理进度
62- // @param persistentId
63- // @callbackFunc (err, respBody, respInfo) - 回调函数
64- OperationManager . prototype . prefop = function ( persistentId , callbackFunc ) {
65- var apiHost = 'api.qiniu.com' ;
82+ /**
83+ * 查询持久化数据处理进度
84+ * @param {string } persistentId
85+ * @param {OperationCallback } callbackFunc 回调函数
86+ */
87+ OperationManager . prototype . prefop = function (
88+ persistentId ,
89+ callbackFunc
90+ ) {
91+ let apiHost = 'api.qiniu.com' ;
6692 if ( this . config . zone ) {
6793 apiHost = this . config . zone . apiHost ;
6894 }
6995
70- var scheme = this . config . useHttpsDomain ? 'https://' : 'http://' ;
71- var requestURI = scheme + apiHost + '/status/get/prefop' ;
72- var reqParams = {
96+ const scheme = this . config . useHttpsDomain ? 'https://' : 'http://' ;
97+ const requestURI = scheme + apiHost + '/status/get/prefop' ;
98+ const reqParams = {
7399 id : persistentId
74100 } ;
75- var reqBody = querystring . stringify ( reqParams ) ;
101+ const reqBody = querystring . stringify ( reqParams ) ;
76102 rpc . postWithForm ( requestURI , reqBody , null , callbackFunc ) ;
77103} ;
0 commit comments