Skip to content

Commit 46957e5

Browse files
author
Cao Jiannan
authored
Revert Combine
Revert Combine
1 parent d7fb777 commit 46957e5

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

qiniu/rs.js

Lines changed: 26 additions & 3 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','fsizeMin', 'detectMime', 'mimeLimit', 'deleteAfterDays'];
226+
var attrs = ['scope', 'insertOnly', 'saveKey', 'endUser', 'returnUrl', 'returnBody', 'callbackUrl', 'callbackHost', 'callbackBody', 'callbackBodyType', 'callbackFetchKey', 'persistentOps', 'persistentNotifyUrl', 'persistentPipeline', 'fsizeLimit', 'detectMime', 'mimeLimit'];
227227

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

275275
}
276276

277-
PutPolicy2.prototype.token = PutPolicy.prototype.token
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);
278300

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

281304
function GetPolicy(expires) {
282305
this.expires = expires || 3600;

0 commit comments

Comments
 (0)