* Attempts to download a file, trying GitHub first and falling back to mirror if needed * @param {string} version Version to download * @param {string} packageName Package filename * @param {string} tempFilename Destination path * @param {boolean} preferMirror Whether to prefer mirror source *
(version, packageName, tempFilename, preferMirror = false)
| 90 | * @returns {Promise<void>} |
| 91 | */ |
| 92 | async function downloadWithFallback(version, packageName, tempFilename, preferMirror = false) { |
| 93 | const sources = preferMirror |
| 94 | ? [ |
| 95 | { name: 'GitCode mirror', baseUrl: GITCODE_RELEASE_BASE_URL }, |
| 96 | { name: 'GitHub', baseUrl: GITHUB_RELEASE_BASE_URL } |
| 97 | ] |
| 98 | : [ |
| 99 | { name: 'GitHub', baseUrl: GITHUB_RELEASE_BASE_URL }, |
| 100 | { name: 'GitCode mirror', baseUrl: GITCODE_RELEASE_BASE_URL } |
| 101 | ] |
| 102 | |
| 103 | let lastError = null |
| 104 | |
| 105 | for (const source of sources) { |
| 106 | const downloadUrl = `${source.baseUrl}/${version}/${packageName}` |
| 107 | console.log(`Trying ${source.name}: ${downloadUrl}`) |
| 108 | |
| 109 | try { |
| 110 | await downloadWithRedirects(downloadUrl, tempFilename) |
| 111 | console.log(`Downloaded successfully from ${source.name}`) |
| 112 | return |
| 113 | } catch (error) { |
| 114 | console.warn(`Failed to download from ${source.name}: ${error.message}`) |
| 115 | lastError = error |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | throw lastError || new Error('All download sources failed') |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Downloads and extracts the openclaw binary for the specified platform and architecture |
no test coverage detected