Skip to content

Commit ea6f697

Browse files
committed
整理代码,将节点路径提出。
1 parent 9be2e85 commit ea6f697

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

lib/utils.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ var _ = require('underscore');
66
XMLHttpRequest: false, XDomainRequest: false, exports: false,
77
require: false */
88
module.exports = function(AV) {
9+
10+
var config = {
11+
cnApiUrl: 'https://leancloud.cn',
12+
usApiUrl: 'https://us-api.leancloud.cn'
13+
};
14+
915
/**
1016
* Contains all AV API classes and functions.
1117
* @name AV
@@ -71,9 +77,6 @@ module.exports = function(AV) {
7177
return child;
7278
};
7379

74-
// Set the server for AV to talk to.
75-
AV.serverURL = "https://api.leancloud.cn";
76-
7780
// Check whether we are running in Node.js.
7881
if (typeof(process) !== "undefined" &&
7982
process.versions &&
@@ -147,20 +150,22 @@ module.exports = function(AV) {
147150
};
148151
}
149152

150-
151153
/**
152154
*Use china avoscloud API service:https://cn.avoscloud.com
153155
*/
154-
AV.useAVCloudCN = function(){
155-
AV.serverURL = "https://leancloud.cn";
156-
};
156+
AV.useAVCloudCN = function(){
157+
AV.serverURL = config.cnApiUrl;
158+
};
157159

158-
/**
159-
*Use USA avoscloud API service:https://us.avoscloud.com
160-
*/
161-
AV.useAVCloudUS = function(){
162-
AV.serverURL = "https://us-api.leancloud.cn";
163-
};
160+
/**
161+
*Use USA avoscloud API service:https://us.avoscloud.com
162+
*/
163+
AV.useAVCloudUS = function(){
164+
AV.serverURL = config.usApiUrl;
165+
};
166+
167+
168+
AV.useAVCloudCN();
164169

165170
/**
166171
* Returns prefix for localStorage keys used by this instance of AV.
@@ -422,7 +427,7 @@ module.exports = function(AV) {
422427
return AV._getInstallationId();
423428
}).then(function(_InstallationId) {
424429
dataObject._InstallationId = _InstallationId;
425-
430+
426431
var data = JSON.stringify(dataObject);
427432
return AV._ajax(method, url, data).then(null, function(response) {
428433
// Transform the error into an instance of AV.Error by trying to parse
@@ -552,8 +557,9 @@ module.exports = function(AV) {
552557
if (value.__op) {
553558
return AV.Op._decode(value);
554559
}
560+
var className;
555561
if (value.__type === "Pointer") {
556-
var className = value.className;
562+
className = value.className;
557563
var pointer = AV.Object._create(className);
558564
if(value.createdAt){
559565
delete value.__type;
@@ -566,7 +572,7 @@ module.exports = function(AV) {
566572
}
567573
if (value.__type === "Object") {
568574
// It's an Object included in a query result.
569-
var className = value.className;
575+
className = value.className;
570576
delete value.__type;
571577
delete value.className;
572578
var object = AV.Object._create(className);

0 commit comments

Comments
 (0)