@@ -2,15 +2,40 @@ 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 } /tools/${ osInfo . platform } /${ osInfo . arch } ` ;
31+ }
732
833// 确保 __dirname 有值,如果没有则使用当前工作目录
934const srcDir = __dirname || "" ;
1035// 确保目标目录有值,空字符串会导致解压到当前目录
1136const destDir = process . env . AILY_TOOLS_PATH || "" ;
1237const _7zaPath = process . env . AILY_7ZA_PATH || "" ;
13- const zipDownloadBaseUrl = process . env . AILY_ZIP_URL + '/tools' ;
38+ const zipDownloadBaseUrl = getZipBaseUrl ( ) ;
1439
1540
1641// 重试函数封装
@@ -205,12 +230,12 @@ async function extractArchives() {
205230 } , 3 , 2000 ) ; // 最多重试3次,每次间隔2秒
206231 console . log ( `已解压 ${ fileName } 到 ${ destDir } ` ) ;
207232
208- // 解压成功后重命名文件夹(将@替换为_)
209- try {
210- await renameExtractedFolder ( fileName , destDir ) ;
211- } catch ( renameErr ) {
212- throw new Error ( `重命名文件夹失败: ${ renameErr . message } ` ) ;
213- }
233+ // // 解压成功后重命名文件夹(将@替换为_)
234+ // try {
235+ // await renameExtractedFolder(fileName, destDir);
236+ // } catch (renameErr) {
237+ // throw new Error(`重命名文件夹失败: ${renameErr.message}`);
238+ // }
214239
215240 // 解压成功后可以删除压缩文件
216241 // fs.unlinkSync(zipFilePath);
0 commit comments