Skip to content

Commit 9510700

Browse files
committed
Merge pull request #188 from wangxiao/master
fix upload file in LeanEngine will use AWS.
2 parents d216264 + d489d06 commit 9510700

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ JavaScript SDK for [LeanCloud](http://leancloud.cn/).
1515
* 在本地进行调试,`npm install` 安装相关依赖
1616
* 执行 `gulp browserify` 会生成浏览器 SDK
1717
* 执行 `gulp release` 会生成全部版本的 SDK
18-
* 服务环境可以通过单元测试调试 `gulp test`,浏览器环境打开 test/test.html
19-
* 确保测试全部通过
18+
* 服务环境通过 mocha 调试单个文件,如调试 file.js `mocha test file`
19+
* 浏览器环境打开 test/test.html
20+
* 确保测试全部通过 `gulp test`
2021
* 提交并发起 Pull Request
2122

2223
项目的目录结构说明如下:

lib/file.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,21 @@ module.exports = function(AV) {
5050
return chunks.join("");
5151
};
5252

53+
// 取出 dataURL 中 base64 的部分
5354
var dataURLToBase64 = function(base64) {
5455
if (base64.split(',')[0] && base64.split(',')[0].indexOf('base64') >= 0) {
5556
base64 = base64.split(',')[1];
5657
}
5758
return base64;
5859
};
5960

61+
// 判断是否是国内节点
62+
var isCnNode = function() {
63+
var serverHost = AV.serverURL.match(/\/\/(.*)/, 'g')[1];
64+
var cnApiHost = AV._config.cnApiUrl.match(/\/\/(.*)/, 'g')[1];
65+
return serverHost === cnApiHost;
66+
}
67+
6068
// A list of file extensions to mime types as found here:
6169
// http://stackoverflow.com/questions/58510/using-net-how-can-you-find-the-
6270
// mime-type-of-a-file-based-on-the-file-signature
@@ -585,7 +593,8 @@ module.exports = function(AV) {
585593
var self = this;
586594
if (!self._previousSave) {
587595
// 如果是国内节点
588-
if(self._source && AV.serverURL === AV._config.cnApiUrl) {
596+
var isCnNodeFlag = isCnNode();
597+
if(self._source && isCnNodeFlag) {
589598
// 通过国内 CDN 服务商上传
590599
var upload = require('./browserify-wrapper/upload');
591600
upload(self, AV, saveOptions);
@@ -607,7 +616,7 @@ module.exports = function(AV) {
607616
}
608617
return self;
609618
});
610-
} else if (AV.serverURL !== AV._config.cnApiUrl) {
619+
} else if (!isCnNodeFlag) {
611620
// 海外节点,通过 LeanCloud 服务器中转
612621
self._previousSave = self._source.then(function(file, type) {
613622
var data = {

0 commit comments

Comments
 (0)