()
| 265 | const config = loadConfig(); |
| 266 | if (config.timeout) { |
| 267 | DEFAULT_TIMEOUT = config.timeout; |
| 268 | } |
| 269 | |
| 270 | async function downloadCli(): Promise<void> { |
| 271 | if (fs.existsSync(SPEEDTEST_PATH)) return; |
| 272 | console.log("Downloading Speedtest CLI..."); |
| 273 | const platform = process.platform; |
| 274 | const arch = process.arch; |
| 275 | let filename: string; |
| 276 | |
| 277 | if (platform === "linux") { |
| 278 | const archMap: { [key: string]: string } = { |
| 279 | x64: "x86_64", |
| 280 | arm64: "aarch64", |
| 281 | arm: "armhf", |
| 282 | }; |
| 283 | const mappedArch = archMap[arch] || "x86_64"; |
| 284 | filename = `ookla-speedtest-${SPEEDTEST_VERSION}-linux-${mappedArch}.tgz`; |
| 285 | } else { |
| 286 | throw new Error(`Unsupported platform for auto-download: ${platform}`); |
| 287 | } |
| 288 | |
| 289 | const url = `https://install.speedtest.net/app/cli/${filename}`; |
| 290 | const response = await axios.get(url, { responseType: "arraybuffer" }); |
| 291 | const tempFile = path.join(ASSETS_DIR, filename); |
| 292 | fs.writeFileSync(tempFile, response.data); |
| 293 | |
| 294 | await execFileAsync("tar", ["-xzf", tempFile, "-C", ASSETS_DIR]); |
| 295 | await execFileAsync("chmod", ["+x", SPEEDTEST_PATH]); |
| 296 | fs.unlinkSync(tempFile); |
| 297 | |
| 298 | ["speedtest.5", "speedtest.md"].forEach((file) => { |
| 299 | const filePath = path.join(ASSETS_DIR, file); |
| 300 | if (fs.existsSync(filePath)) fs.unlinkSync(filePath); |
| 301 | }); |
| 302 | console.log("Speedtest CLI downloaded and extracted successfully."); |
| 303 | } |
no test coverage detected