@@ -17,6 +17,7 @@ const crypto_1 = __importDefault(require("crypto"));
1717const portfinder_1 = __importDefault ( require ( "portfinder" ) ) ;
1818const query_string_1 = __importDefault ( require ( "query-string" ) ) ;
1919const open_1 = __importDefault ( require ( "open" ) ) ;
20+ const address_1 = __importDefault ( require ( "address" ) ) ;
2021var cli_table_1 = require ( "./cli-table" ) ;
2122exports . printCliTable = cli_table_1 . printCliTable ;
2223const store_1 = require ( "./store" ) ;
@@ -37,17 +38,15 @@ function getPort() {
3738 } ) ;
3839}
3940function getMacAddress ( ) {
40- const networkInterfaces = os_1 . default . networkInterfaces ( ) ;
41- const options = [ 'eth0' , 'eth1' , 'en0' , 'en1' ] ;
42- let netInterface = [ ] ;
43- options . some ( key => {
44- if ( networkInterfaces [ key ] ) {
45- netInterface = networkInterfaces [ key ] ;
46- return true ;
47- }
41+ return new Promise ( resolve => {
42+ address_1 . default . mac ( ( err , mac ) => {
43+ if ( err ) {
44+ resolve ( '' ) ;
45+ return ;
46+ }
47+ resolve ( mac ) ;
48+ } ) ;
4849 } ) ;
49- const mac = ( netInterface . length && netInterface [ 0 ] . mac ) || '' ;
50- return mac ;
5150}
5251function getOSInfo ( ) {
5352 const hostname = os_1 . default . hostname ( ) ;
@@ -63,7 +62,7 @@ function md5(str) {
6362}
6463function refreshTmpToken ( metaData ) {
6564 return __awaiter ( this , void 0 , void 0 , function * ( ) {
66- const mac = getMacAddress ( ) ;
65+ const mac = yield getMacAddress ( ) ;
6766 const hash = md5 ( mac ) ;
6867 metaData . hash = hash ;
6968 const res = yield utils_1 . fetch ( refreshTokenUrl , {
@@ -148,9 +147,12 @@ function getAuthTokenFromWeb() {
148147 loading . start ( '正在打开腾讯云获取授权' ) ;
149148 try {
150149 const { server, port } = yield createLocalServer ( ) ;
151- const mac = getMacAddress ( ) ;
150+ const mac = yield getMacAddress ( ) ;
152151 const os = getOSInfo ( ) ;
153152 const hash = md5 ( mac ) ;
153+ if ( ! mac ) {
154+ throw new error_1 . CloudBaseError ( '获取 Mac 地址失败,无法登录!' ) ;
155+ }
154156 const CliAuthUrl = `${ CliAuthBaseUrl } ?port=${ port } &hash=${ hash } &mac=${ mac } &os=${ os } ` ;
155157 yield open_1 . default ( CliAuthUrl ) ;
156158 loading . succeed ( '已打开云开发 CLI 授权页面,请在云开发 CLI 授权页面同意授权!' ) ;
0 commit comments