@@ -9,14 +9,53 @@ document.addEventListener('DOMContentLoaded', () => {
99 updateDownloadLinks ( ) ;
1010} ) ;
1111
12+ function normalizeReleaseVersion ( value ) {
13+ return String ( value || '' ) . trim ( ) . replace ( / ^ v / i, '' ) ;
14+ }
15+
16+ function compareVersions ( left , right ) {
17+ const leftParts = normalizeReleaseVersion ( left ) . split ( '.' ) . map ( part => Number . parseInt ( part , 10 ) || 0 ) ;
18+ const rightParts = normalizeReleaseVersion ( right ) . split ( '.' ) . map ( part => Number . parseInt ( part , 10 ) || 0 ) ;
19+ const maxLength = Math . max ( leftParts . length , rightParts . length ) ;
20+
21+ for ( let index = 0 ; index < maxLength ; index += 1 ) {
22+ const leftPart = leftParts [ index ] || 0 ;
23+ const rightPart = rightParts [ index ] || 0 ;
24+
25+ if ( leftPart > rightPart ) return 1 ;
26+ if ( leftPart < rightPart ) return - 1 ;
27+ }
28+
29+ return 0 ;
30+ }
31+
32+ function getAssetVersion ( name ) {
33+ const match = String ( name || '' ) . match ( / ( \d + \. \d + \. \d + ) / ) ;
34+ return match ? match [ 1 ] : '' ;
35+ }
36+
37+ function pickReleaseAsset ( assets , matcher , releaseVersion ) {
38+ const candidates = ( assets || [ ] ) . filter ( asset => matcher ( asset ?. name || '' ) ) ;
39+ if ( ! candidates . length ) return null ;
40+
41+ const normalizedReleaseVersion = normalizeReleaseVersion ( releaseVersion ) ;
42+ const exactMatch = candidates . find ( asset => getAssetVersion ( asset . name ) === normalizedReleaseVersion ) ;
43+ if ( exactMatch ) return exactMatch ;
44+
45+ return candidates
46+ . slice ( )
47+ . sort ( ( left , right ) => compareVersions ( getAssetVersion ( right . name ) , getAssetVersion ( left . name ) ) ) [ 0 ] ;
48+ }
49+
1250async function updateDownloadLinks ( ) {
1351 try {
1452 const response = await fetch ( 'https://api.github.com/repos/JeffGepiga/DevBoxPro/releases/latest' ) ;
1553 const data = await response . json ( ) ;
1654
1755 if ( data && data . assets ) {
18- const setupAsset = data . assets . find ( a => a . name . includes ( 'Setup' ) && a . name . endsWith ( '.exe' ) ) ;
19- const portableAsset = data . assets . find ( a => ! a . name . includes ( 'Setup' ) && a . name . endsWith ( '.exe' ) ) ;
56+ const releaseVersion = data . tag_name || data . name ;
57+ const setupAsset = pickReleaseAsset ( data . assets , name => / s e t u p / i. test ( name ) && name . endsWith ( '.exe' ) , releaseVersion ) ;
58+ const portableAsset = pickReleaseAsset ( data . assets , name => ! / s e t u p / i. test ( name ) && name . endsWith ( '.exe' ) , releaseVersion ) ;
2059
2160 if ( setupAsset ) {
2261 document . querySelectorAll ( '.download-setup-btn' ) . forEach ( btn => {
0 commit comments