@@ -4,6 +4,7 @@ const INFERA_API_BASE_URL = process.env.INFERA_API_BASE_URL || process.env.VITE_
44const CLIENT_RELEASES_URL = `${ INFERA_API_BASE_URL . replace ( / \/ + $ / , "" ) } /client/releases` ;
55const LATEST_RELEASE_API_URL = `${ CLIENT_RELEASES_URL } /latest` ;
66const RELEASES_URL = `${ CLIENT_RELEASES_URL } /latest` ;
7+ const UPDATE_CHECK_TIMEOUT_MS = 60000 ;
78
89function normalizeVersion ( value ) {
910 return String ( value || "" )
@@ -31,15 +32,36 @@ function getReleaseVersion(release) {
3132 return normalizeVersion ( release ?. tag_name || release ?. name ) ;
3233}
3334
34- function scoreAsset ( asset , platform ) {
35- const name = String ( asset ?. name || "" ) . toLowerCase ( ) ;
36- if ( ! asset ?. browser_download_url || name . endsWith ( ".blockmap" ) || name . endsWith ( ".yml" ) ) return 0 ;
35+ function getAssetName ( asset ) {
36+ return String ( asset ?. name || asset ?. assetName || "" ) . toLowerCase ( ) ;
37+ }
38+
39+ function getAssetDownloadUrl ( asset ) {
40+ return asset ?. browser_download_url || asset ?. downloadUrl || "" ;
41+ }
42+
43+ function getAssetArch ( asset ) {
44+ const arch = String ( asset ?. arch || "" ) . toLowerCase ( ) ;
45+ if ( arch === "x64" || arch === "x86_64" ) return "x64" ;
46+ if ( arch === "arm64" || arch === "aarch64" ) return "arm64" ;
47+
48+ const name = getAssetName ( asset ) ;
49+ if ( name . includes ( "x64" ) || name . includes ( "x86_64" ) ) return "x64" ;
50+ if ( name . includes ( "arm64" ) || name . includes ( "aarch64" ) ) return "arm64" ;
51+ return "" ;
52+ }
53+
54+ function scoreAsset ( asset , platform , arch = process . arch ) {
55+ const name = getAssetName ( asset ) ;
56+ if ( ! getAssetDownloadUrl ( asset ) || name . endsWith ( ".blockmap" ) || name . endsWith ( ".yml" ) ) return 0 ;
3757
3858 if ( platform === "darwin" ) {
39- if ( ( name . includes ( "dl-studio-mac" ) || name . includes ( "dl-editor-mac" ) ) && name . endsWith ( ".dmg" ) ) return 30 ;
40- if ( ( name . includes ( "dl-studio-mac" ) || name . includes ( "dl-editor-mac" ) ) && name . endsWith ( ".pkg" ) ) return 20 ;
41- if ( name . endsWith ( ".dmg" ) ) return 10 ;
42- if ( name . endsWith ( ".pkg" ) ) return 5 ;
59+ const assetArch = getAssetArch ( asset ) ;
60+ const archScore = ! assetArch ? 1 : assetArch === arch ? 20 : - 100 ;
61+ if ( ( name . includes ( "dl-studio-mac" ) || name . includes ( "dl-editor-mac" ) ) && name . endsWith ( ".dmg" ) ) return 30 + archScore ;
62+ if ( ( name . includes ( "dl-studio-mac" ) || name . includes ( "dl-editor-mac" ) ) && name . endsWith ( ".pkg" ) ) return 20 + archScore ;
63+ if ( name . endsWith ( ".dmg" ) ) return 10 + archScore ;
64+ if ( name . endsWith ( ".pkg" ) ) return 5 + archScore ;
4365 }
4466
4567 if ( platform === "win32" ) {
@@ -51,13 +73,13 @@ function scoreAsset(asset, platform) {
5173 return 0 ;
5274}
5375
54- function selectDownloadAsset ( release , platform = process . platform ) {
76+ function selectDownloadAsset ( release , platform = process . platform , arch = process . arch ) {
5577 const assets = Array . isArray ( release ?. assets ) ? release . assets : [ ] ;
5678 let selected = null ;
5779 let selectedScore = 0 ;
5880
5981 for ( const asset of assets ) {
60- const assetScore = scoreAsset ( asset , platform ) ;
82+ const assetScore = scoreAsset ( asset , platform , arch ) ;
6183 if ( assetScore > selectedScore ) {
6284 selected = asset ;
6385 selectedScore = assetScore ;
@@ -67,7 +89,7 @@ function selectDownloadAsset(release, platform = process.platform) {
6789 return selected ;
6890}
6991
70- function buildUpdateResult ( { currentVersion, platform = process . platform , release } ) {
92+ function buildUpdateResult ( { currentVersion, platform = process . platform , arch = process . arch , release } ) {
7193 const latestVersion = getReleaseVersion ( release ) ;
7294 if ( ! latestVersion ) {
7395 throw new Error ( "更新数据缺少版本号。" ) ;
@@ -88,16 +110,16 @@ function buildUpdateResult({ currentVersion, platform = process.platform, releas
88110 return { ...base , status : "latest" } ;
89111 }
90112
91- const asset = selectDownloadAsset ( release , platform ) ;
113+ const asset = selectDownloadAsset ( release , platform , arch ) ;
92114 if ( ! asset ) {
93115 return { ...base , status : "no_asset" } ;
94116 }
95117
96118 return {
97119 ...base ,
98120 status : "available" ,
99- assetName : asset . name ,
100- downloadUrl : asset . browser_download_url
121+ assetName : asset . name || asset . assetName || "" ,
122+ downloadUrl : getAssetDownloadUrl ( asset )
101123 } ;
102124}
103125
@@ -123,7 +145,7 @@ function requestJson(url) {
123145 Accept : "application/vnd.github+json" ,
124146 "User-Agent" : "DL-Studio-Updater"
125147 } ,
126- timeout : 15000
148+ timeout : UPDATE_CHECK_TIMEOUT_MS
127149 } ,
128150 ( response ) => {
129151 let body = "" ;
@@ -155,7 +177,7 @@ function requestJson(url) {
155177 } ) ;
156178}
157179
158- async function checkForUpdate ( { currentVersion, platform = process . platform , apiUrl = LATEST_RELEASE_API_URL } = { } ) {
180+ async function checkForUpdate ( { currentVersion, platform = process . platform , arch = process . arch , apiUrl = LATEST_RELEASE_API_URL } = { } ) {
159181 let release ;
160182 try {
161183 release = await requestJson ( apiUrl ) ;
@@ -166,11 +188,12 @@ async function checkForUpdate({ currentVersion, platform = process.platform, api
166188 throw error ;
167189 }
168190
169- return buildUpdateResult ( { currentVersion, platform, release } ) ;
191+ return buildUpdateResult ( { currentVersion, platform, arch , release } ) ;
170192}
171193
172194module . exports = {
173195 LATEST_RELEASE_API_URL ,
196+ UPDATE_CHECK_TIMEOUT_MS ,
174197 buildNoReleaseResult,
175198 buildUpdateResult,
176199 checkForUpdate,
0 commit comments