1-
21var url = require ( 'url' ) ;
32var crypto = require ( 'crypto' ) ;
43var formstream = require ( 'formstream' ) ;
@@ -59,11 +58,11 @@ Client.prototype.copy = function(bucketSrc, keySrc, bucketDest, keyDest, onret)
5958}
6059
6160Client . prototype . fetch = function ( url , bucket , key , onret ) {
62- var bucketUri = getEncodedEntryUri ( bucket , key ) ;
63- var fetchUrl = util . urlsafeBase64Encode ( url ) ;
64- var uri = 'http://iovip.qbox.me/fetch/' + fetchUrl + '/to/' + bucketUri ;
65- var digest = util . generateAccessToken ( uri , null ) ;
66- rpc . postWithoutForm ( uri , digest , onret ) ;
61+ var bucketUri = getEncodedEntryUri ( bucket , key ) ;
62+ var fetchUrl = util . urlsafeBase64Encode ( url ) ;
63+ var uri = 'http://iovip.qbox.me/fetch/' + fetchUrl + '/to/' + bucketUri ;
64+ var digest = util . generateAccessToken ( uri , null ) ;
65+ rpc . postWithoutForm ( uri , digest , onret ) ;
6766}
6867
6968function Entry ( hash , fsize , putTime , mimeType , endUser ) {
@@ -142,17 +141,35 @@ function getEncodedEntryUri(bucket, key) {
142141
143142// ----- token --------
144143// @gist PutPolicy
145- function PutPolicy ( scope , callbackUrl , callbackBody , returnUrl , returnBody ,
146- asyncOps , endUser , expires , persistentOps , persistentNotifyUrl ) {
147- this . scope = scope || null ;
148- this . callbackUrl = callbackUrl || null ;
149- this . callbackBody = callbackBody || null ;
150- this . returnUrl = returnUrl || null ;
151- this . returnBody = returnBody || null ;
152- this . endUser = endUser || null ;
153- this . expires = expires || 3600 ;
154- this . persistentOps = persistentOps || null ;
155- this . persistentNotifyUrl = persistentNotifyUrl || null ;
144+ function PutPolicy ( putPolicyObj ) {
145+
146+ if ( typeof putPolicyObj !== 'object' ) {
147+ return false ;
148+ }
149+
150+ this . scope = putPolicyObj . scope || null ;
151+ this . expires = putPolicyObj . expires || 3600 ;
152+ this . insertOnly = putPolicyObj . insertOnly || null ;
153+
154+ this . saveKey = putPolicyObj . saveKey || null ;
155+ this . endUser = putPolicyObj . endUser || null ;
156+
157+ this . returnUrl = putPolicyObj . returnUrl || null ;
158+ this . returnBody = putPolicyObj . returnBody || null ;
159+
160+ this . callbackUrl = putPolicyObj . callbackUrl || null ;
161+ this . callbackHost = putPolicyObj . callbackHost || null ;
162+ this . callbackBody = putPolicyObj . callbackBody || null ;
163+
164+ this . persistentOps = putPolicyObj . persistentOps || null ;
165+ this . persistentNotifyUrl = putPolicyObj . persistentNotifyUrl || null ;
166+ this . persistentPipeline = putPolicyObj . persistentPipeline || null ;
167+
168+ this . fsizeLimit = putPolicyObj . fsizeLimit || null ;
169+
170+ this . detectMime = putPolicyObj . detectMime || null ;
171+
172+ this . mimeLimit = putPolicyObj . mimeLimit || null ;
156173}
157174// @endgist
158175
@@ -168,26 +185,40 @@ PutPolicy.prototype.token = function(mac) {
168185 return uploadToken ;
169186}
170187
171- PutPolicy . prototype . getFlags = function ( putPolicy ) {
188+ PutPolicy . prototype . getFlags = function ( ) {
172189 var flags = { } ;
173190 if ( this . scope != null ) {
174191 flags [ 'scope' ] = this . scope ;
175192 }
176- if ( this . callbackUrl != null ) {
177- flags [ 'callbackUrl' ] = this . callbackUrl ;
193+ flags [ 'deadline' ] = this . expires + Math . floor ( Date . now ( ) / 1000 ) ;
194+ if ( this . insertOnly != null ) {
195+ flags [ 'insertOnly' ] = this . insertOnly ;
178196 }
179- if ( this . callbackBody != null ) {
180- flags [ 'callbackBody' ] = this . callbackBody ;
197+
198+ if ( this . saveKey != null ) {
199+ flags [ 'saveKey' ] = this . saveKey ;
200+ }
201+ if ( this . endUser != null ) {
202+ flags [ 'endUser' ] = this . endUser ;
181203 }
204+
182205 if ( this . returnUrl != null ) {
183206 flags [ 'returnUrl' ] = this . returnUrl ;
184207 }
185208 if ( this . returnBody != null ) {
186209 flags [ 'returnBody' ] = this . returnBody ;
187210 }
188- if ( this . endUser != null ) {
189- flags [ 'endUser' ] = this . endUser ;
211+
212+ if ( this . callbackUrl != null ) {
213+ flags [ 'callbackUrl' ] = this . callbackUrl ;
214+ }
215+ if ( this . callbackHost != null ) {
216+ flags [ 'callbackHost' ] = this . callbackHost ;
190217 }
218+ if ( this . callbackBody != null ) {
219+ flags [ 'callbackBody' ] = this . callbackBody ;
220+ }
221+
191222 if ( this . persistentOps != null ) {
192223 flags [ 'persistentOps' ] = this . persistentOps ;
193224 }
@@ -197,25 +228,19 @@ PutPolicy.prototype.getFlags = function(putPolicy) {
197228 if ( this . persistentPipeline != null ) {
198229 flags [ 'persistentPipeline' ] = this . persistentPipeline ;
199230 }
200- if ( this . mimeLimit != null ) {
201- flags [ 'mimeLimit' ] = this . mimeLimit ;
202- }
203- if ( this . insertOnly != null ) {
204- flags [ 'insertOnly' ] = this . insertOnly ;
231+
232+ if ( this . fsizeLimit != null ) {
233+ flags [ 'fsizeLimit' ] = this . fsizeLimit ;
205234 }
235+
206236 if ( this . detectMime != null ) {
207237 flags [ 'detectMime' ] = this . detectMime ;
208238 }
209- if ( this . saveKey != null ) {
210- flags [ 'saveKey' ] = this . saveKey ;
211- }
212- flags [ 'deadline' ] = this . expires + Math . floor ( Date . now ( ) / 1000 ) ;
213- if ( this . fsizeLimit != null ) {
214- flags [ 'fsizeLimit' ] = this . fsizeLimit ;
215- }
216- if ( this . insertOnly != null ) {
217- flags [ 'insertOnly' ] = this . insertOnly ;
239+
240+ if ( this . mimeLimit != null ) {
241+ flags [ 'mimeLimit' ] = this . mimeLimit ;
218242 }
243+
219244 return flags ;
220245}
221246
@@ -246,5 +271,5 @@ GetPolicy.prototype.makeRequest = function(baseUrl, mac) {
246271// query like '-thumbnail', '?imageMogr2/thumbnail/960x' and so on
247272function makeBaseUrl ( domain , key , query ) {
248273 key = new Buffer ( key ) ;
249- return 'http://' + domain + '/' + querystring . escape ( key ) + ( query || '' ) ;
274+ return 'http://' + domain + '/' + querystring . escape ( key ) + ( query || '' ) ;
250275}
0 commit comments