Skip to content

Commit 9b844c4

Browse files
authored
feat: add support for pfop workflow template (#439)
1 parent a013e5c commit 9b844c4

File tree

7 files changed

+120
-13
lines changed

7 files changed

+120
-13
lines changed

.github/workflows/ci-test.yml

+2
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,5 @@ jobs:
3232
QINIU_TEST_DOMAIN: ${{ secrets.QINIU_TEST_DOMAIN }}
3333
- name: Upload coverage reports
3434
uses: codecov/codecov-action@v4
35+
with:
36+
token: ${{ secrets.CODECOV_TOKEN }}

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## CHANGE LOG
22

3+
## 7.14.0
4+
- 对象存储,持久化处理支持工作流模版
5+
- 对象存储,修复持久化处理闲时任务的类型声明
6+
37
## 7.13.0
48
- 对象存储,新增空间级别上传加速开关
59
- 对象存储,优化断点续传开启方式

index.d.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,11 @@ export declare namespace fop {
10551055
* 为 `1` 时开启闲时任务
10561056
*/
10571057
type?: number;
1058+
1059+
/**
1060+
* 工作流模版 ID,与函数参数中的 fops 参数二选一
1061+
*/
1062+
workflowTemplateID?: string
10581063
}
10591064
class OperationManager {
10601065
mac: auth.digest.Mac;
@@ -1066,7 +1071,7 @@ export declare namespace fop {
10661071
* 发送持久化数据处理请求
10671072
* @param bucket 空间名称
10681073
* @param key 文件名称
1069-
* @param fops 处理指令集合
1074+
* @param fops 处理指令集合,与 options.workflowTemplateID 二选一
10701075
* @param pipeline 处理队列名称
10711076
* @param options
10721077
* @param callback
@@ -1097,15 +1102,17 @@ export declare namespace fop {
10971102
reqid: string,
10981103
inputBucket: string,
10991104
inputKey: string,
1100-
creationDate: string,
1101-
type: number,
1105+
creationDate?: string,
1106+
type?: number,
1107+
taskFrom?: string,
11021108
items: {
11031109
cmd: string,
11041110
code: number,
11051111
desc: string,
11061112
returnOld: number,
11071113
error?: string,
11081114
hash?: string,
1115+
key?: string,
11091116
}[]
11101117
}>
11111118
): void;
@@ -1779,7 +1786,8 @@ export declare namespace rs {
17791786
persistentOps?: string;
17801787
persistentNotifyUrl?: string;
17811788
persistentPipeline?: string;
1782-
persistentType?: string;
1789+
persistentType?: number;
1790+
persistentWorkflowTemplateID?: string;
17831791

17841792
fsizeLimit?: number;
17851793
fsizeMin?: number;

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "qiniu",
3-
"version": "7.13.0",
3+
"version": "7.14.0",
44
"description": "Node wrapper for Qiniu Resource (Cloud) Storage API",
55
"main": "index.js",
66
"directories": {

qiniu/fop.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ function OperationManager (mac, config) {
2424
* @param {string} [options.notifyURL] 回调业务服务器,通知处理结果
2525
* @param {boolean} [options.force] 是否强制覆盖已有的同名文件
2626
* @param {string} [options.type] 为 `1` 时,开启闲时任务
27+
* @param {string} [options.workflowTemplateID] 工作流模板 ID
2728
* @param {OperationCallback} callbackFunc 回调函数
2829
*/
2930
OperationManager.prototype.pfop = function (
@@ -38,9 +39,12 @@ OperationManager.prototype.pfop = function (
3839
// 必须参数
3940
const reqParams = {
4041
bucket: bucket,
41-
key: key,
42-
fops: fops.join(';')
42+
key: key
4343
};
44+
// `fops` is optional by could use `options.workflowTemplateID` to work
45+
if (Array.isArray(fops)) {
46+
reqParams.fops = fops.join(';');
47+
}
4448

4549
// pipeline
4650
if (!pipeline) {
@@ -57,9 +61,14 @@ OperationManager.prototype.pfop = function (
5761
reqParams.force = 1;
5862
}
5963

64+
// workflowTemplateID
65+
if (options.workflowTemplateID) {
66+
reqParams.workflowTemplateID = options.workflowTemplateID;
67+
}
68+
6069
const persistentType = parseInt(options.type, 10);
6170
if (!isNaN(persistentType)) {
62-
reqParams.type = options.type;
71+
reqParams.type = persistentType;
6372
}
6473

6574
util.prepareZone(this, this.mac.accessKey, bucket, function (err, ctx) {

qiniu/storage/rs.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1692,10 +1692,11 @@ function _putPolicyBuildInKeys () {
16921692
* @property {string} [callbackBody]
16931693
* @property {string} [callbackBodyType]
16941694
* @property {number} [callbackFetchKey]
1695-
* @property {string} [persistentOps]
1695+
* @property {string} [persistentOps] conflict with `persistentWorkflowTemplateID`
16961696
* @property {string} [persistentNotifyUrl]
16971697
* @property {string} [persistentPipeline]
1698-
* @property {string} [persistentType]
1698+
* @property {number} [persistentType]
1699+
* @property {string} [persistentWorkflowTemplateID] conflict with `persistentOps`
16991700
* @property {number} [fsizeLimit]
17001701
* @property {number} [fsizeMin]
17011702
* @property {string} [mimeLimit]

test/fop.test.js

+86-3
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ describe('test start fop', function () {
129129

130130
it(`test pfop with upload; ${msg}`, function () {
131131
const formUploader = new qiniu.form_up.FormUploader(config);
132-
const key = 'qiniu-pfop-upload-file';
132+
const key = 'test-pfop/upload-file';
133133
const persistentKey = [
134-
'qiniu-pfop-by-upload',
135-
'persistentType',
134+
'test-pfop/test-pfop-by-upload',
135+
'type',
136136
persistentType
137137
].join('_');
138138

@@ -179,4 +179,87 @@ describe('test start fop', function () {
179179
});
180180
});
181181
});
182+
183+
it('test pfop by templateID with api', function () {
184+
const srcKey = 'qiniu.mp4';
185+
const srcBucket = bucketName;
186+
187+
const templateID = 'test-workflow';
188+
const operationManager = new qiniu.fop.OperationManager(mac, config);
189+
190+
new Promise((resolve, reject) => {
191+
operationManager.pfop(
192+
srcBucket,
193+
srcKey,
194+
null,
195+
null,
196+
{ workflowTemplateID: templateID },
197+
function (err, respBody, respInfo) {
198+
if (err) {
199+
reject(err);
200+
return;
201+
}
202+
resolve({ data: respBody, resp: respInfo });
203+
}
204+
);
205+
})
206+
.then(({ data }) => {
207+
data.should.have.keys('persistentId');
208+
return new Promise((resolve, reject) => {
209+
operationManager.prefop(
210+
data.persistentId,
211+
function (err, respBody, respInfo) {
212+
if (err) {
213+
reject(err);
214+
return;
215+
}
216+
resolve({ data: respBody, resp: respInfo });
217+
}
218+
);
219+
});
220+
})
221+
.then(({ data }) => {
222+
data.should.have.keys(
223+
'creationDate',
224+
'taskFrom'
225+
);
226+
});
227+
});
228+
229+
it('test pfop by templateID with upload', function () {
230+
const formUploader = new qiniu.form_up.FormUploader(config);
231+
const key = 'qiniu-pfop-tplid-upload-file';
232+
const templateID = 'test-workflow';
233+
const options = {
234+
scope: bucketName,
235+
persistentWorkflowTemplateID: templateID
236+
};
237+
const putPolicy = new qiniu.rs.PutPolicy(options);
238+
const uploadToken = putPolicy.uploadToken(mac);
239+
const putExtra = new qiniu.form_up.PutExtra();
240+
241+
return formUploader.put(uploadToken, key, testFilePath, putExtra)
242+
.then(({ data }) => {
243+
data.should.have.keys('key', 'persistentId');
244+
return new Promise((resolve, reject) => {
245+
new qiniu.fop.OperationManager(mac, config)
246+
.prefop(
247+
data.persistentId,
248+
function (err, respBody, respInfo) {
249+
if (err) {
250+
reject(err);
251+
return;
252+
}
253+
resolve({ data: respBody, resp: respInfo });
254+
}
255+
);
256+
});
257+
})
258+
.then(({ data }) => {
259+
data.should.have.keys(
260+
'creationDate',
261+
'taskFrom'
262+
);
263+
});
264+
});
182265
});

0 commit comments

Comments
 (0)