|
1 | 1 | /*! |
2 | 2 | * AVOSCloud JavaScript SDK |
3 | | - * Version: 0.4.5 |
| 3 | + * Version: 0.4.6 |
4 | 4 | * Built: Mon Jun 03 2013 13:45:00 |
5 | 5 | * http://avoscloud.com |
6 | 6 | * |
|
13 | 13 | */ |
14 | 14 | (function(root) { |
15 | 15 | root.AV = root.AV || {}; |
16 | | - root.AV.VERSION = "js0.4.5"; |
| 16 | + root.AV.VERSION = "js0.4.6"; |
17 | 17 | }(this)); |
18 | 18 | // Underscore.js 1.4.4 |
19 | 19 | // http://underscorejs.org |
|
1364 | 1364 | * This method is for AV's own private use. |
1365 | 1365 | * @param {String} applicationId Your AV Application ID. |
1366 | 1366 | * @param {String} applicationKey Your AV Application Key |
1367 | | -
|
1368 | 1367 | */ |
1369 | 1368 | AV._initialize = function(applicationId, applicationKey, masterKey) { |
1370 | 1369 | AV.applicationId = applicationId; |
|
1373 | 1372 | AV._useMasterKey = false; |
1374 | 1373 | }; |
1375 | 1374 |
|
| 1375 | + |
| 1376 | + /** |
| 1377 | + * Call this method to set production environment variable. |
| 1378 | + * @param {Boolean} production, true is production environment,and |
| 1379 | + * it's true by default. |
| 1380 | + */ |
| 1381 | + AV.setProduction = function(production){ |
| 1382 | + if(!AV._isNullOrUndefined(production)) { |
| 1383 | + //make sure it's a number |
| 1384 | + production = production ? 1 : 0; |
| 1385 | + } |
| 1386 | + //default is 1 |
| 1387 | + AV.applicationProduction = AV._isNullOrUndefined(production) ? 1: production; |
| 1388 | + } |
| 1389 | + |
1376 | 1390 | // If we're running in node.js, allow using the master key. |
1377 | 1391 | if (AV._isNode) { |
1378 | 1392 | AV.initialize = AV._initialize; |
|
1626 | 1640 |
|
1627 | 1641 | dataObject._ApplicationId = AV.applicationId; |
1628 | 1642 | dataObject._ApplicationKey = AV.applicationKey; |
| 1643 | + if(!AV._isNullOrUndefined(AV.applicationProduction)) { |
| 1644 | + dataObject._ApplicationProduction = AV.applicationProduction; |
| 1645 | + } |
1629 | 1646 | if(AV._useMasterKey) |
1630 | 1647 | dataObject._MasterKey = AV.masterKey; |
1631 | 1648 | dataObject._ClientVersion = AV.VERSION; |
|
1717 | 1734 | return value.toJSON(); |
1718 | 1735 | } |
1719 | 1736 | if (value instanceof AV.File) { |
1720 | | - if (!value.url()) { |
| 1737 | + if (!value.url() && !value.id) { |
1721 | 1738 | throw "Tried to save an object containing an unsaved file."; |
1722 | 1739 | } |
1723 | 1740 | return { |
|
4128 | 4145 | * @param {String} Optional Content-Type header to use for the file. If |
4129 | 4146 | * this is omitted, the content type will be inferred from the name's |
4130 | 4147 | * extension. |
| 4148 | + * @return {AV.File} the file object |
4131 | 4149 | */ |
4132 | 4150 | AV.File.withURL = function(name, url, metaData, type){ |
4133 | 4151 | if(!name || !url){ |
|
4147 | 4165 | return file; |
4148 | 4166 | }; |
4149 | 4167 |
|
| 4168 | + /** |
| 4169 | + * Creates a file object with exists objectId. |
| 4170 | + * @param {String} The objectId string |
| 4171 | + * @return {AV.File} the file object |
| 4172 | + */ |
| 4173 | + AV.File.createWithoutData = function(objectId){ |
| 4174 | + var file = new AV.File(); |
| 4175 | + file.id = objectId; |
| 4176 | + return file; |
| 4177 | + }; |
| 4178 | + |
4150 | 4179 | AV.File.prototype = { |
4151 | 4180 |
|
| 4181 | + /** |
| 4182 | + * Returns the ACL for this file. |
| 4183 | + * @returns {AV.ACL} An instance of AV.ACL. |
| 4184 | + */ |
| 4185 | + getACL: function() { |
| 4186 | + return this._acl; |
| 4187 | + }, |
| 4188 | + |
| 4189 | + /** |
| 4190 | + * Sets the ACL to be used for this file. |
| 4191 | + * @param {AV.ACL} acl An instance of AV.ACL. |
| 4192 | + */ |
| 4193 | + setACL: function(acl) { |
| 4194 | + if(!(acl instanceof AV.ACL)) { |
| 4195 | + return new AV.Error(AV.Error.OTHER_CAUSE, |
| 4196 | + "ACL must be a AV.ACL."); |
| 4197 | + } |
| 4198 | + this._acl = acl; |
| 4199 | + }, |
| 4200 | + |
4152 | 4201 | /** |
4153 | 4202 | * Gets the name of the file. Before save is called, this is the filename |
4154 | 4203 | * given by the user. After save is called, that name gets prefixed with a |
|
4264 | 4313 | var key = hexOctet() + hexOctet() + hexOctet() + hexOctet(); |
4265 | 4314 | var data = { |
4266 | 4315 | key: key, |
| 4316 | + ACL: self._acl, |
4267 | 4317 | name:self._name, |
4268 | 4318 | mime_type: type, |
4269 | 4319 | metaData: self._metaData, |
|
4303 | 4353 | var data = { |
4304 | 4354 | base64: base64, |
4305 | 4355 | _ContentType: type, |
| 4356 | + ACL: self._acl, |
4306 | 4357 | mime_type: type, |
4307 | 4358 | metaData: self._metaData, |
4308 | 4359 | }; |
|
4317 | 4368 | }); |
4318 | 4369 | } |
4319 | 4370 | } else if(self._url && self._metaData['__source'] == 'external') { |
| 4371 | + //external link file. |
4320 | 4372 | var data = { |
4321 | 4373 | name: self._name, |
| 4374 | + ACL: self._acl, |
4322 | 4375 | metaData: self._metaData, |
4323 | 4376 | mime_type: self._guessedType, |
4324 | 4377 | url: self._url |
|
5680 | 5733 | } |
5681 | 5734 |
|
5682 | 5735 | if (object instanceof AV.File) { |
5683 | | - if (!object.url()) { |
| 5736 | + if (!object.url() && !object.id) { |
5684 | 5737 | files.push(object); |
5685 | 5738 | } |
5686 | 5739 | return; |
|
7524 | 7577 | return query; |
7525 | 7578 | }; |
7526 | 7579 |
|
| 7580 | + /** |
| 7581 | + * Constructs a AV.Query that is the AND of the passed in queries. For |
| 7582 | + * example: |
| 7583 | + * <pre>var compoundQuery = AV.Query.and(query1, query2, query3);</pre> |
| 7584 | + * |
| 7585 | + * will create a compoundQuery that is an 'and' of the query1, query2, and |
| 7586 | + * query3. |
| 7587 | + * @param {...AV.Query} var_args The list of queries to AND. |
| 7588 | + * @return {AV.Query} The query that is the AND of the passed in queries. |
| 7589 | + */ |
| 7590 | + AV.Query.and = function() { |
| 7591 | + var queries = _.toArray(arguments); |
| 7592 | + var className = null; |
| 7593 | + AV._arrayEach(queries, function(q) { |
| 7594 | + if (_.isNull(className)) { |
| 7595 | + className = q.className; |
| 7596 | + } |
| 7597 | + |
| 7598 | + if (className !== q.className) { |
| 7599 | + throw "All queries must be for the same class"; |
| 7600 | + } |
| 7601 | + }); |
| 7602 | + var query = new AV.Query(className); |
| 7603 | + query._andQuery(queries); |
| 7604 | + return query; |
| 7605 | + }; |
| 7606 | + |
7527 | 7607 | /** |
7528 | 7608 | * Retrieves a list of AVObjects that satisfy the CQL. |
7529 | 7609 | * CQL syntax please see <a href='https://cn.avoscloud.com/docs/cql_guide.html'>CQL Guide.</a> |
|
8001 | 8081 | return this; |
8002 | 8082 | }, |
8003 | 8083 |
|
| 8084 | + /** |
| 8085 | + * Add constraint that both of the passed in queries matches. |
| 8086 | + * @param {Array} queries |
| 8087 | + * @return {AV.Query} Returns the query, so you can chain this call. |
| 8088 | + */ |
| 8089 | + _andQuery: function(queries) { |
| 8090 | + var queryJSON = _.map(queries, function(q) { |
| 8091 | + return q.toJSON().where; |
| 8092 | + }); |
| 8093 | + |
| 8094 | + this._where.$and = queryJSON; |
| 8095 | + return this; |
| 8096 | + }, |
| 8097 | + |
| 8098 | + |
8004 | 8099 | /** |
8005 | 8100 | * Converts a string into a regex that matches it. |
8006 | 8101 | * Surrounding with \Q .. \E does this, we just need to escape \E's in |
|
8925 | 9020 | * @return {AV.Promise} A promise that will be resolved with the result |
8926 | 9021 | * of the function. |
8927 | 9022 | */ |
8928 | | - verifySmsCode: function(code, options){ |
| 9023 | + verifySmsCode: function(code, phone, options){ |
8929 | 9024 | if(!code) |
8930 | 9025 | throw "Missing sms code."; |
| 9026 | + var params = {}; |
| 9027 | + if(AV._.isString(phone)) { |
| 9028 | + params['mobilePhoneNumber'] = phone; |
| 9029 | + } else { |
| 9030 | + // To be compatible with old versions. |
| 9031 | + options = phone; |
| 9032 | + } |
| 9033 | + |
8931 | 9034 | var request = AV._request("verifySmsCode", code, null, 'POST', |
8932 | | - null); |
| 9035 | + params); |
8933 | 9036 | return request._thenRunCallbacks(options); |
8934 | 9037 | } |
8935 | 9038 | }); |
|
0 commit comments