Skip to content

Commit 85967c9

Browse files
committed
Merge pull request #126 from zedgu/develop
add callbackFetchKey for flags and improve the code
2 parents ecaf534 + 94a905b commit 85967c9

File tree

1 file changed

+6
-50
lines changed

1 file changed

+6
-50
lines changed

qiniu/rs.js

Lines changed: 6 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -187,59 +187,15 @@ PutPolicy.prototype.token = function(mac) {
187187

188188
PutPolicy.prototype.getFlags = function() {
189189
var flags = {};
190-
if (this.scope != null) {
191-
flags['scope'] = this.scope;
192-
}
193-
flags['deadline'] = this.expires + Math.floor(Date.now() / 1000);
194-
if (this.insertOnly != null) {
195-
flags['insertOnly'] = this.insertOnly;
196-
}
197-
198-
if (this.saveKey != null) {
199-
flags['saveKey'] = this.saveKey;
200-
}
201-
if (this.endUser != null) {
202-
flags['endUser'] = this.endUser;
203-
}
190+
var attrs = ['scope', 'insertOnly', 'saveKey', 'endUser', 'returnUrl', 'returnBody', 'callbackUrl', 'callbackHost', 'callbackBody', 'callbackBodyType', 'callbackFetchKey', 'persistentOps', 'persistentNotifyUrl', 'persistentPipeline', 'fsizeLimit', 'detectMime', 'mimeLimit'];
204191

205-
if (this.returnUrl != null) {
206-
flags['returnUrl'] = this.returnUrl;
207-
}
208-
if (this.returnBody != null) {
209-
flags['returnBody'] = this.returnBody;
210-
}
211-
212-
if (this.callbackUrl != null) {
213-
flags['callbackUrl'] = this.callbackUrl;
214-
}
215-
if (this.callbackHost != null) {
216-
flags['callbackHost'] = this.callbackHost;
217-
}
218-
if (this.callbackBody != null) {
219-
flags['callbackBody'] = this.callbackBody;
192+
for (var i = attrs.length - 1; i >= 0; i--) {
193+
if (this[attrs[i]] !== null) {
194+
flags[attrs[i]] = this[attrs[i]];
195+
}
220196
}
221197

222-
if (this.persistentOps != null) {
223-
flags['persistentOps'] = this.persistentOps;
224-
}
225-
if (this.persistentNotifyUrl != null) {
226-
flags['persistentNotifyUrl'] = this.persistentNotifyUrl;
227-
}
228-
if (this.persistentPipeline != null) {
229-
flags['persistentPipeline'] = this.persistentPipeline;
230-
}
231-
232-
if (this.fsizeLimit != null) {
233-
flags['fsizeLimit'] = this.fsizeLimit;
234-
}
235-
236-
if (this.detectMime != null) {
237-
flags['detectMime'] = this.detectMime;
238-
}
239-
240-
if (this.mimeLimit != null) {
241-
flags['mimeLimit'] = this.mimeLimit;
242-
}
198+
flags['deadline'] = this.expires + Math.floor(Date.now() / 1000);
243199

244200
return flags;
245201
}

0 commit comments

Comments
 (0)