File tree Expand file tree Collapse file tree 5 files changed +56
-1
lines changed Expand file tree Collapse file tree 5 files changed +56
-1
lines changed Original file line number Diff line number Diff line change @@ -351,6 +351,15 @@ PutExtra是上传时的可选信息,默认为null
351
351
@gist(gist/fop.js#makeImageViewUrl)
352
352
```
353
353
354
+ ### 实用函数
355
+
356
+ #### 测试是否来自七牛的callback
357
+ 在上传的` putPolicy ` 中指定` callbackUrl ` 和` callbackBody ` ,在上传成功后七牛会有一个回调函数,这个函数用来检测回调是否来自七牛。
358
+
359
+ ``` {javascript}
360
+ @gist(../test/rs.test.js#isQiniuCallback)
361
+ ```
362
+
354
363
## 贡献代码
355
364
356
365
+ Fork
Original file line number Diff line number Diff line change @@ -174,7 +174,8 @@ function uptoken(bucketname) {
174
174
//putPolicy.callbackBody = callbackBody;
175
175
//putPolicy.returnUrl = returnUrl;
176
176
//putPolicy.returnBody = returnBody;
177
- //putPolicy.asyncOps = asyncOps;
177
+ //putpolicy.persistentOps = persistentops;
178
+ //putPolicy.persistentNotifyUrl = persistentNotifyUrl;
178
179
//putPolicy.expires = expires;
179
180
180
181
return putPolicy.token();
@@ -584,6 +585,22 @@ url = policy.makeRequest(url);
584
585
console.log('在浏览器输入: ' + url);
585
586
```
586
587
588
+ ### 实用函数
589
+
590
+ #### 测试是否来自七牛的callback
591
+ 在上传的` putPolicy ` 中指定` callbackUrl ` 和` callbackBody ` ,在上传成功后七牛会有一个回调函数,这个函数用来检测回调是否来自七牛。
592
+
593
+ ``` {javascript}
594
+ // ------ auth应该是来自请求的header的'Authrization'字段,path是请求的路径,content是请求的内容
595
+ var auth = 'QBox nnwjTeUgpQdfZp9cb4-iHK0EUlebKCNk4kXwoStq:kyFuG6yYh6FlX1fZO0alTgJK2Jw=';
596
+ var path = '/callback';
597
+ var content = 'key=43850.6579994258936495&hash=FllOJrhvzorEKnyMwE-o7pfciiha';
598
+ // ------
599
+
600
+ var ok = qiniu.util.isQiniuCallback(path, content, auth);
601
+ ok.should.be.ok;
602
+ ```
603
+
587
604
## 贡献代码
588
605
589
606
+ Fork
Original file line number Diff line number Diff line change @@ -7,4 +7,6 @@ module.exports = {
7
7
rsf : require ( libpath + '/rsf.js' ) ,
8
8
fop : require ( libpath + '/fop.js' ) ,
9
9
conf : require ( libpath + '/conf.js' ) ,
10
+ rpc : require ( libpath + '/rpc.js' ) ,
11
+ util : require ( libpath + '/util.js' ) ,
10
12
} ;
Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ var path = require('path');
4
4
var crypto = require ( 'crypto' ) ;
5
5
var conf = require ( './conf' ) ;
6
6
7
+ exports . isQiniuCallback = isQiniuCallback ;
8
+
7
9
// ------------------------------------------------------------------------------------------
8
10
// func encode
9
11
@@ -41,3 +43,9 @@ exports.generateAccessToken = function(uri, body) {
41
43
var safeDigest = exports . base64ToUrlSafe ( digest ) ;
42
44
return 'QBox ' + conf . ACCESS_KEY + ':' + safeDigest ;
43
45
}
46
+
47
+ function isQiniuCallback ( path , body , callbackAuth ) {
48
+
49
+ var auth = exports . generateAccessToken ( path , body )
50
+ return auth === callbackAuth ;
51
+ }
Original file line number Diff line number Diff line change @@ -164,6 +164,25 @@ describe('test start step2:', function() {
164
164
} ) ;
165
165
} ) ;
166
166
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
+
167
186
// rs.GetPolicy#makeRequest()
168
187
169
188
} ) ;
You can’t perform that action at this time.
0 commit comments