Skip to content

Commit d7fb777

Browse files
author
frogcjn
committed
combine token/getFlags prototype function in PutPolicy
1 parent 3b33a09 commit d7fb777

File tree

1 file changed

+3
-26
lines changed

1 file changed

+3
-26
lines changed

qiniu/rs.js

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ PutPolicy.prototype.token = function(mac) {
223223

224224
PutPolicy.prototype.getFlags = function() {
225225
var flags = {};
226-
var attrs = ['scope', 'insertOnly', 'saveKey', 'endUser', 'returnUrl', 'returnBody', 'callbackUrl', 'callbackHost', 'callbackBody', 'callbackBodyType', 'callbackFetchKey', 'persistentOps', 'persistentNotifyUrl', 'persistentPipeline', 'fsizeLimit', 'detectMime', 'mimeLimit'];
226+
var attrs = ['scope', 'insertOnly', 'saveKey', 'endUser', 'returnUrl', 'returnBody', 'callbackUrl', 'callbackHost', 'callbackBody', 'callbackBodyType', 'callbackFetchKey', 'persistentOps', 'persistentNotifyUrl', 'persistentPipeline', 'fsizeLimit','fsizeMin', 'detectMime', 'mimeLimit', 'deleteAfterDays'];
227227

228228
for (var i = attrs.length - 1; i >= 0; i--) {
229229
if (this[attrs[i]] !== null) {
@@ -274,32 +274,9 @@ function PutPolicy2(putPolicyObj) {
274274

275275
}
276276

277-
PutPolicy2.prototype.token = function(mac) {
278-
if (mac == null) {
279-
mac = new Mac(conf.ACCESS_KEY, conf.SECRET_KEY);
280-
}
281-
var flags = this.getFlags();
282-
var encodedFlags = util.urlsafeBase64Encode(JSON.stringify(flags));
283-
var encoded = util.hmacSha1(encodedFlags, mac.secretKey);
284-
var encodedSign = util.base64ToUrlSafe(encoded);
285-
var uploadToken = mac.accessKey + ':' + encodedSign + ':' + encodedFlags;
286-
return uploadToken;
287-
}
288-
289-
PutPolicy2.prototype.getFlags = function() {
290-
var flags = {};
291-
var attrs = ['scope', 'insertOnly', 'saveKey', 'endUser', 'returnUrl', 'returnBody', 'callbackUrl', 'callbackHost', 'callbackBody', 'callbackBodyType', 'callbackFetchKey', 'persistentOps', 'persistentNotifyUrl', 'persistentPipeline', 'fsizeLimit','fsizeMin', 'detectMime', 'mimeLimit', 'deleteAfterDays'];
292-
293-
for (var i = attrs.length - 1; i >= 0; i--) {
294-
if (this[attrs[i]] !== null) {
295-
flags[attrs[i]] = this[attrs[i]];
296-
}
297-
}
298-
299-
flags['deadline'] = this.expires + Math.floor(Date.now() / 1000);
277+
PutPolicy2.prototype.token = PutPolicy.prototype.token
300278

301-
return flags;
302-
}
279+
PutPolicy2.prototype.getFlags = PutPolicy.prototype.getFlags
303280

304281
function GetPolicy(expires) {
305282
this.expires = expires || 3600;

0 commit comments

Comments
 (0)