Skip to content

Commit e42e9ca

Browse files
committed
Merge pull request #102 from qiniu/develop
Release 6.1.3
2 parents 3d1cda3 + ee7bb7a commit e42e9ca

File tree

9 files changed

+139
-1
lines changed

9 files changed

+139
-1
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
## CHANGE LOG
22

3+
### v6.1.3
4+
5+
2014-4-03 issue [#102](https://github.com/qiniu/nodejs-sdk/pull/102)
6+
7+
- [#98] 增加pfop 功能
8+
- [#99] 增加针对七牛callback的检查
9+
310
### v6.1.2
411

512
2014-2-17 issue [#96](https://github.com/qiniu/nodejs-sdk/pull/96)

docs/README.gist.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,19 @@ PutExtra是上传时的可选信息,默认为null
333333
### 云处理
334334

335335
<a云处理使用说明\>
336+
337+
#### pfop
338+
`pfop`的作用是对已存在七牛服务器上的文件做持久化的fop,具体见[api文档](http://developer.qiniu.com/docs/v6/api/overview/fop/persistent-fop.html)
339+
340+
```{javascript}
341+
// 原型
342+
func pfop(bucketName, keyName, fops, opts, callback);
343+
344+
// 例子
345+
@gist(../test/io.test.js#pfop)
346+
347+
```
348+
336349
#### 查看图像信息
337350

338351
```{javascript}
@@ -351,6 +364,15 @@ PutExtra是上传时的可选信息,默认为null
351364
@gist(gist/fop.js#makeImageViewUrl)
352365
```
353366

367+
### 实用函数
368+
369+
#### 测试是否来自七牛的callback
370+
在上传的`putPolicy`中指定`callbackUrl``callbackBody`,在上传成功后七牛会有一个回调函数,这个函数用来检测回调是否来自七牛。
371+
372+
```{javascript}
373+
@gist(../test/rs.test.js#isQiniuCallback)
374+
```
375+
354376
## 贡献代码
355377

356378
+ Fork

docs/README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ function uptoken(bucketname) {
174174
//putPolicy.callbackBody = callbackBody;
175175
//putPolicy.returnUrl = returnUrl;
176176
//putPolicy.returnBody = returnBody;
177-
//putPolicy.asyncOps = asyncOps;
177+
//putpolicy.persistentOps = persistentops;
178+
//putPolicy.persistentNotifyUrl = persistentNotifyUrl;
178179
//putPolicy.expires = expires;
179180
180181
return putPolicy.token();
@@ -529,6 +530,23 @@ qiniu.rsf.listPrefix(bucketname, prefix, marker, limit, function(err, ret) {
529530
### 云处理
530531

531532
<a云处理使用说明\>
533+
534+
#### pfop
535+
`pfop`的作用是对已存在七牛服务器上的文件做持久化的fop,具体见[api文档](http://developer.qiniu.com/docs/v6/api/overview/fop/persistent-fop.html)
536+
537+
```{javascript}
538+
// 原型
539+
func pfop(bucketName, keyName, fops, opts, callback);
540+
541+
// 例子
542+
// pfop
543+
qiniu.fop.pfop(TEST_BUCKET, keys[0], 'avinfo', {notifyUrl: 'www.test.com', force: true}, function(err, ret) {
544+
ret.should.have.keys('persistentId');
545+
done();
546+
});
547+
548+
```
549+
532550
#### 查看图像信息
533551

534552
```{javascript}
@@ -584,6 +602,22 @@ url = policy.makeRequest(url);
584602
console.log('在浏览器输入: ' + url);
585603
```
586604

605+
### 实用函数
606+
607+
#### 测试是否来自七牛的callback
608+
在上传的`putPolicy`中指定`callbackUrl``callbackBody`,在上传成功后七牛会有一个回调函数,这个函数用来检测回调是否来自七牛。
609+
610+
```{javascript}
611+
// ------ auth应该是来自请求的header的'Authrization'字段,path是请求的路径,content是请求的内容
612+
var auth = 'QBox nnwjTeUgpQdfZp9cb4-iHK0EUlebKCNk4kXwoStq:kyFuG6yYh6FlX1fZO0alTgJK2Jw=';
613+
var path = '/callback';
614+
var content = 'key=43850.6579994258936495&hash=FllOJrhvzorEKnyMwE-o7pfciiha';
615+
// ------
616+
617+
var ok = qiniu.util.isQiniuCallback(path, content, auth);
618+
ok.should.be.ok;
619+
```
620+
587621
## 贡献代码
588622

589623
+ Fork

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ module.exports = {
77
rsf: require(libpath + '/rsf.js'),
88
fop: require(libpath + '/fop.js'),
99
conf: require(libpath + '/conf.js'),
10+
rpc: require(libpath + '/rpc.js'),
11+
util: require(libpath + '/util.js')
1012
};

qiniu/fop.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
var util = require('./util');
2+
var rpc = require('./rpc');
13

4+
var querystring = require('querystring');
25

36
exports.ImageView = ImageView;
47
exports.ImageInfo = ImageInfo;
58
exports.Exif = Exif;
9+
exports.pfop = pfop;
610

711
function ImageView(mode, width, height, quality, format) {
812
this.mode = mode || 1;
@@ -49,3 +53,27 @@ Exif.prototype.makeRequest = function(url) {
4953
}
5054

5155

56+
function pfop(bucket, key, fops, opts, onret) {
57+
58+
opts = opts || {};
59+
60+
param = {
61+
bucket: bucket,
62+
key: key,
63+
fops: fops
64+
};
65+
if (opts.notifyURL) {
66+
param.notifyURL = opts.notifyURL;
67+
} else {
68+
param.notifyURL = 'www.test.com';
69+
}
70+
if (opts.force) {
71+
param.force = 1;
72+
}
73+
74+
var uri = 'http://api.qiniu.com/pfop/';
75+
var body = querystring.stringify(param);
76+
var auth = util.generateAccessToken(uri, body);
77+
rpc.postWithForm(uri, body, auth, onret);
78+
}
79+

qiniu/rs.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ PutPolicy.prototype.getFlags = function(putPolicy) {
183183
if (this.endUser != null) {
184184
flags['endUser'] = this.endUser;
185185
}
186+
if (this.persistentOps != null) {
187+
flags['persistentOps'] = this.persistentOps;
188+
}
189+
if (this.persistentNotifyUrl != null) {
190+
flags['persistentNotifyUrl'] = this.persistentNotifyUrl;
191+
}
186192
flags['deadline'] = this.expires + Math.floor(Date.now() / 1000);
187193
return flags;
188194
}

qiniu/util.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ var path = require('path');
44
var crypto = require('crypto');
55
var conf = require('./conf');
66

7+
exports.isQiniuCallback = isQiniuCallback;
8+
79
// ------------------------------------------------------------------------------------------
810
// func encode
911

@@ -41,3 +43,9 @@ exports.generateAccessToken = function(uri, body) {
4143
var safeDigest = exports.base64ToUrlSafe(digest);
4244
return 'QBox ' + conf.ACCESS_KEY + ':' + safeDigest;
4345
}
46+
47+
function isQiniuCallback(path, body, callbackAuth) {
48+
49+
var auth = exports.generateAccessToken(path, body)
50+
return auth === callbackAuth;
51+
}

test/io.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,16 @@ describe('test start step1:', function() {
133133
});
134134
});
135135
});
136+
137+
describe('pfop', function() {
138+
it('do pfop', function(done) {
139+
// @gist pfop
140+
// pfop
141+
qiniu.fop.pfop(TEST_BUCKET, keys[0], 'avinfo', {notifyURL: 'www.test.com'}, function(err, ret) {
142+
ret.should.have.keys('persistentId');
143+
done();
144+
});
145+
// @endgist
146+
})
147+
});
136148
});

test/rs.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,25 @@ describe('test start step2:', function() {
164164
});
165165
});
166166

167+
describe('rs.isQiniuCallBack', function() {
168+
169+
it('test isQiniuCallback true', function(done) {
170+
// @gist isQiniuCallback
171+
// ------ auth应该是来自请求的header的'Authrization'字段,path是请求的路径,content是请求的内容
172+
var auth = 'QBox nnwjTeUgpQdfZp9cb4-iHK0EUlebKCNk4kXwoStq:kyFuG6yYh6FlX1fZO0alTgJK2Jw=';
173+
var path = '/callback';
174+
var content = 'key=43850.6579994258936495&hash=FllOJrhvzorEKnyMwE-o7pfciiha';
175+
// ------
176+
177+
var ok = qiniu.util.isQiniuCallback(path, content, auth);
178+
ok.should.be.ok;
179+
// @endgist
180+
done();
181+
});
182+
183+
184+
});
185+
167186
// rs.GetPolicy#makeRequest()
168187

169188
});

0 commit comments

Comments
 (0)