Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita013e5c

Browse files
authored
Add support for fop persistent type (#438)
* test: rename util func `checkEnvConfigAndExit` to `checkEnvConfigOrExit`* feat: add idle-time fop support and type declaration
1 parente0c2426 commita013e5c

File tree

9 files changed

+274
-103
lines changed

9 files changed

+274
-103
lines changed

‎index.d.ts‎

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
StatObjectResult
2121
}from"./StorageResponseInterface";
2222

23-
exportdeclaretypecallback=(e?:Error,respBody?:any,respInfo?:any)=>void;
23+
exportdeclaretypecallback<T=any>=(e?:Error,respBody?:T,respInfo?:any)=>void;
2424

2525
exportdeclarenamespaceauth{
2626
namespacedigest{
@@ -1050,6 +1050,11 @@ export declare namespace fop {
10501050
* 结果是否强制覆盖已有的同名文件
10511051
*/
10521052
force?:boolean;
1053+
1054+
/**
1055+
* 为 `1` 时开启闲时任务
1056+
*/
1057+
type?:number;
10531058
}
10541059
classOperationManager{
10551060
mac:auth.digest.Mac;
@@ -1066,14 +1071,44 @@ export declare namespace fop {
10661071
*@param options
10671072
*@param callback
10681073
*/
1069-
pfop(bucket:string,key:string,fops:string[],pipeline:string,options:PfopOptions|null,callback:callback):void;
1074+
pfop(
1075+
bucket:string,
1076+
key:string,
1077+
fops:string[],
1078+
pipeline:string,
1079+
options:PfopOptions|null,
1080+
callback:callback<{
1081+
persistentId:string
1082+
}>
1083+
):void;
10701084

10711085
/**
10721086
* 查询持久化数据处理进度
1073-
*@param persistentIdpfop操作返回的持久化处理ID
1087+
*@param persistentIdpfop 操作返回的持久化处理ID
10741088
*@param callback
10751089
*/
1076-
prefop(persistentId:string,callback:callback):void;
1090+
prefop(
1091+
persistentId:string,
1092+
callback:callback<{
1093+
id:string,
1094+
pipeline:string,
1095+
code:number,
1096+
desc:string,
1097+
reqid:string,
1098+
inputBucket:string,
1099+
inputKey:string,
1100+
creationDate:string,
1101+
type:number,
1102+
items:{
1103+
cmd:string,
1104+
code:number,
1105+
desc:string,
1106+
returnOld:number,
1107+
error?:string,
1108+
hash?:string,
1109+
}[]
1110+
}>
1111+
):void;
10771112
}
10781113
}
10791114

@@ -1744,6 +1779,7 @@ export declare namespace rs {
17441779
persistentOps?:string;
17451780
persistentNotifyUrl?:string;
17461781
persistentPipeline?:string;
1782+
persistentType?:string;
17471783

17481784
fsizeLimit?:number;
17491785
fsizeMin?:number;

‎qiniu/fop.js‎

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,42 @@ function OperationManager (mac, config) {
1111
this.config=config||newconf.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-
varreqParams={
39+
constreqParams={
2840
bucket:bucket,
2941
key:key,
30-
pipeline:pipeline,
3142
fops:fops.join(';')
3243
};
3344

45+
// pipeline
46+
if(!pipeline){
47+
deletereqParams.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+
constpersistentType=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

5374
functionpfopReq(mac,config,reqParams,callbackFunc){
54-
varscheme=config.useHttpsDomain ?'https://' :'http://';
55-
varrequestURI=scheme+config.zone.apiHost+'/pfop/';
56-
varreqBody=querystring.stringify(reqParams);
57-
varauth=util.generateAccessToken(mac,requestURI,reqBody);
75+
constscheme=config.useHttpsDomain ?'https://' :'http://';
76+
constrequestURI=scheme+config.zone.apiHost+'/pfop/';
77+
constreqBody=querystring.stringify(reqParams);
78+
constauth=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-
varapiHost='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+
letapiHost='api.qiniu.com';
6692
if(this.config.zone){
6793
apiHost=this.config.zone.apiHost;
6894
}
6995

70-
varscheme=this.config.useHttpsDomain ?'https://' :'http://';
71-
varrequestURI=scheme+apiHost+'/status/get/prefop';
72-
varreqParams={
96+
constscheme=this.config.useHttpsDomain ?'https://' :'http://';
97+
constrequestURI=scheme+apiHost+'/status/get/prefop';
98+
constreqParams={
7399
id:persistentId
74100
};
75-
varreqBody=querystring.stringify(reqParams);
101+
constreqBody=querystring.stringify(reqParams);
76102
rpc.postWithForm(requestURI,reqBody,null,callbackFunc);
77103
};

‎qiniu/storage/form.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ function putReq (
222222
*@param {string | null} key
223223
*@param {any} body
224224
*@param {PutExtra | null} putExtra
225-
*@param {reqCallback} callbackFunc
225+
*@param {reqCallback}[callbackFunc]
226226
*@returns {Promise<UploadResult>}
227227
*/
228228
FormUploader.prototype.put=function(

‎qiniu/storage/rs.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,6 +1695,7 @@ function _putPolicyBuildInKeys () {
16951695
*@property {string} [persistentOps]
16961696
*@property {string} [persistentNotifyUrl]
16971697
*@property {string} [persistentPipeline]
1698+
*@property {string} [persistentType]
16981699
*@property {number} [fsizeLimit]
16991700
*@property {number} [fsizeMin]
17001701
*@property {string} [mimeLimit]

‎test/conftest.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function getEnvConfig () {
1212
}
1313
exports.getEnvConfig=getEnvConfig;
1414

15-
functioncheckEnvConfigAndExit(){
15+
functioncheckEnvConfigOkOrExit(){
1616
constenvConfig=getEnvConfig();
1717
if(
1818
Object.keys(envConfig).some(k=>!envConfig[k])
@@ -21,7 +21,7 @@ function checkEnvConfigAndExit () {
2121
process.exit(0);
2222
}
2323
}
24-
exports.checkEnvConfigAndExit=checkEnvConfigAndExit;
24+
exports.checkEnvConfigOrExit=checkEnvConfigOkOrExit;
2525

2626
/**
2727
*@typedef Param

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp