Comparing version 6.1.7 to 6.1.8
## CHANGE LOG | ||
### v6.1.8 | ||
2015-05-13 | ||
- 上传增加putpolicy2 | ||
### v6.1.7 | ||
@@ -7,3 +13,3 @@ | ||
- 上传策略增加 callbackHost、persistentPipeline, callbackFetchKey | ||
- 上传putpolicy2增加 callbackHost、persistentPipeline, callbackFetchKey | ||
- 增加fetch 函数 | ||
@@ -17,3 +23,3 @@ - imageview -> imageview2 | ||
- 上传策略增加fsizelimit, insertonly | ||
- 上传putpolicy2增加fsizelimit, insertonly | ||
@@ -20,0 +26,0 @@ |
{ | ||
"name": "qiniu", | ||
"version": "6.1.7", | ||
"version": "6.1.8", | ||
"description": "Node wrapper for Qiniu Resource (Cloud) Storage API", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -19,2 +19,3 @@ var url = require('url'); | ||
exports.PutPolicy = PutPolicy; | ||
exports.PutPolicy2 = PutPolicy2; | ||
exports.GetPolicy = GetPolicy; | ||
@@ -145,4 +146,45 @@ exports.makeBaseUrl = makeBaseUrl; | ||
// @gist PutPolicy | ||
function PutPolicy(putPolicyObj) { | ||
function PutPolicy(scope, callbackUrl, callbackBody, returnUrl, returnBody, | ||
asyncOps, endUser, expires, persistentOps, persistentNotifyUrl) { | ||
this.scope = scope || null; | ||
this.callbackUrl = callbackUrl || null; | ||
this.callbackBody = callbackBody || null; | ||
this.returnUrl = returnUrl || null; | ||
this.returnBody = returnBody || null; | ||
this.endUser = endUser || null; | ||
this.expires = expires || 3600; | ||
this.persistentOps = persistentOps || null; | ||
this.persistentNotifyUrl = persistentNotifyUrl || null; | ||
} | ||
// @endgist | ||
PutPolicy.prototype.token = function(mac) { | ||
if (mac == null) { | ||
mac = new Mac(conf.ACCESS_KEY, conf.SECRET_KEY); | ||
} | ||
var flags = this.getFlags(); | ||
var encodedFlags = util.urlsafeBase64Encode(JSON.stringify(flags)); | ||
var encoded = util.hmacSha1(encodedFlags, mac.secretKey); | ||
var encodedSign = util.base64ToUrlSafe(encoded); | ||
var uploadToken = mac.accessKey + ':' + encodedSign + ':' + encodedFlags; | ||
return uploadToken; | ||
} | ||
PutPolicy.prototype.getFlags = function() { | ||
var flags = {}; | ||
var attrs = ['scope', 'insertOnly', 'saveKey', 'endUser', 'returnUrl', 'returnBody', 'callbackUrl', 'callbackHost', 'callbackBody', 'callbackBodyType', 'callbackFetchKey', 'persistentOps', 'persistentNotifyUrl', 'persistentPipeline', 'fsizeLimit', 'detectMime', 'mimeLimit']; | ||
for (var i = attrs.length - 1; i >= 0; i--) { | ||
if (this[attrs[i]] !== null) { | ||
flags[attrs[i]] = this[attrs[i]]; | ||
} | ||
} | ||
flags['deadline'] = this.expires + Math.floor(Date.now() / 1000); | ||
return flags; | ||
} | ||
function PutPolicy2(putPolicyObj) { | ||
if (typeof putPolicyObj !== 'object') { | ||
@@ -176,5 +218,4 @@ return false; | ||
} | ||
// @endgist | ||
PutPolicy.prototype.token = function(mac) { | ||
PutPolicy2.prototype.token = function(mac) { | ||
if (mac == null) { | ||
@@ -191,3 +232,3 @@ mac = new Mac(conf.ACCESS_KEY, conf.SECRET_KEY); | ||
PutPolicy.prototype.getFlags = function() { | ||
PutPolicy2.prototype.getFlags = function() { | ||
var flags = {}; | ||
@@ -194,0 +235,0 @@ var attrs = ['scope', 'insertOnly', 'saveKey', 'endUser', 'returnUrl', 'returnBody', 'callbackUrl', 'callbackHost', 'callbackBody', 'callbackBodyType', 'callbackFetchKey', 'persistentOps', 'persistentNotifyUrl', 'persistentPipeline', 'fsizeLimit', 'detectMime', 'mimeLimit']; |
35577
15
694