@@ -2,17 +2,41 @@ const fs = require('fs');
22const { spawn } = require ( 'child_process' ) ;
33const path = require ( 'path' ) ;
44const https = require ( 'https' ) ;
5+ const os = require ( 'os' ) ;
56
6- // test
7+ // 获取当前操作系统类型
8+ function getOSType ( ) {
9+ const platform = os . platform ( ) ;
10+ let arch = os . arch ( ) ;
11+
12+ // 根据arch判断是intel还是arm架构
13+ if ( arch . startsWith ( 'arm' ) ) {
14+ arch = 'arm' ;
15+ } else {
16+ arch = 'intel' ;
17+ }
18+
19+ return {
20+ platform : platform ,
21+ arch : arch ,
22+ release : os . release ( ) ,
23+ version : os . version ? os . version ( ) : 'N/A'
24+ } ;
25+ }
26+
27+ function getZipBaseUrl ( ) {
28+ const osInfo = getOSType ( ) ;
29+ const baseUrl = process . env . AILY_ZIP_URL || '' ;
30+ return `${ baseUrl } /sdk/${ osInfo . platform } /${ osInfo . arch } ` ;
31+ }
732
8- // test
933
1034// 确保 __dirname 有值,如果没有则使用当前工作目录
1135const srcDir = __dirname || "" ;
1236// 确保目标目录有值,空字符串会导致解压到当前目录
1337const destDir = process . env . AILY_SDK_PATH || "" ;
1438const _7zaPath = process . env . AILY_7ZA_PATH || "" ;
15- const zipDownloadBaseUrl = process . env . AILY_ZIP_URL + '/sdk' ;
39+ const zipDownloadBaseUrl = getZipBaseUrl ( ) ;
1640
1741
1842// 重试函数封装
@@ -181,9 +205,6 @@ async function extractArchives() {
181205 const zipFilePath = path . join ( __dirname , fileName ) ;
182206 try {
183207 const stats = fs . statSync ( zipFilePath ) ;
184- if ( stats . size < 1048576 ) { // 1MB = 1024 * 1024 bytes
185- throw new Error ( `下载的文件异常小 (${ stats . size } 字节),可能下载不完整或被截断` ) ;
186- }
187208 console . log ( `文件大小: ${ ( stats . size / ( 1024 * 1024 ) ) . toFixed ( 2 ) } MB` ) ;
188209 } catch ( statErr ) {
189210 if ( statErr . code === 'ENOENT' ) {
0 commit comments