MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / downloadCli

Function downloadCli

speedlink/speedlink.ts:267–300  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

265const config = loadConfig();
266if (config.timeout) {
267 DEFAULT_TIMEOUT = config.timeout;
268}
269
270async 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}

Callers 1

speedtestFunction · 0.70

Calls 2

execFileAsyncFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected