@@ -11,26 +11,42 @@ function OperationManager (mac, config) {
11
11
this . config = config || new conf . Config ( ) ;
12
12
}
13
13
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
+ ) {
25
37
options = options || { } ;
26
38
// 必须参数
27
- var reqParams = {
39
+ const reqParams = {
28
40
bucket : bucket ,
29
41
key : key ,
30
- pipeline : pipeline ,
31
42
fops : fops . join ( ';' )
32
43
} ;
33
44
45
+ // pipeline
46
+ if ( ! pipeline ) {
47
+ delete reqParams . pipeline ;
48
+ }
49
+
34
50
// notifyURL
35
51
if ( options . notifyURL ) {
36
52
reqParams . notifyURL = options . notifyURL ;
@@ -41,6 +57,11 @@ OperationManager.prototype.pfop = function (bucket, key, fops, pipeline,
41
57
reqParams . force = 1 ;
42
58
}
43
59
60
+ const persistentType = parseInt ( options . type , 10 ) ;
61
+ if ( ! isNaN ( persistentType ) ) {
62
+ reqParams . type = options . type ;
63
+ }
64
+
44
65
util . prepareZone ( this , this . mac . accessKey , bucket , function ( err , ctx ) {
45
66
if ( err ) {
46
67
callbackFunc ( err , null , null ) ;
@@ -51,27 +72,32 @@ OperationManager.prototype.pfop = function (bucket, key, fops, pipeline,
51
72
} ;
52
73
53
74
function 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 ) ;
58
79
rpc . postWithForm ( requestURI , reqBody , auth , callbackFunc ) ;
59
80
}
60
81
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' ;
66
92
if ( this . config . zone ) {
67
93
apiHost = this . config . zone . apiHost ;
68
94
}
69
95
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 = {
73
99
id : persistentId
74
100
} ;
75
- var reqBody = querystring . stringify ( reqParams ) ;
101
+ const reqBody = querystring . stringify ( reqParams ) ;
76
102
rpc . postWithForm ( requestURI , reqBody , null , callbackFunc ) ;
77
103
} ;
0 commit comments