@@ -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