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

Function downloadCli

speedtest/speedtest.ts:243–352  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

241 if (fs.existsSync(SPEEDTEST_PATH)) {
242 console.log(`Speedtest CLI already exists at: ${SPEEDTEST_PATH}`);
243 return;
244 }
245
246 const platform = process.platform;
247 const arch = process.arch;
248 console.log(`Downloading speedtest CLI for platform: ${platform}, arch: ${arch}`);
249
250 let filename: string;
251
252 if (platform === "linux") {
253 const archMap: { [key: string]: string } = {
254 x64: "x86_64",
255 arm64: "aarch64",
256 arm: "armhf",
257 };
258 const mappedArch = archMap[arch] || "x86_64";
259 filename = `ookla-speedtest-${SPEEDTEST_VERSION}-linux-${mappedArch}.tgz`;
260 } else if (platform === "win32") {
261 filename = `ookla-speedtest-${SPEEDTEST_VERSION}-win64.zip`;
262 } else if (platform === "darwin") {
263 // macOS support
264 filename = `ookla-speedtest-${SPEEDTEST_VERSION}-macosx-universal.tgz`;
265 } else {
266 throw new Error(`Unsupported platform: ${platform}`);
267 }
268
269 const url = `https://install.speedtest.net/app/cli/${filename}`;
270 console.log(`Downloading from: ${url}`);
271
272 const response = await axios.get(url, { responseType: "arraybuffer" });
273 const tempFile = path.join(ASSETS_DIR, filename);
274
275 console.log(`Saving to temp file: ${tempFile}`);
276 fs.writeFileSync(tempFile, response.data);
277
278 // 验证文件是否下载成功
279 if (!fs.existsSync(tempFile)) {
280 throw new Error(`Failed to save downloaded file: ${tempFile}`);
281 }
282
283 // 解压文件
284 if (platform === "linux" || platform === "darwin") {
285 console.log(`Extracting tar.gz file: ${tempFile}`);
286 await execAsync(`tar -xzf "${tempFile}" -C "${ASSETS_DIR}"`);
287
288 // 验证可执行文件是否存在
289 if (!fs.existsSync(SPEEDTEST_PATH)) {
290 throw new Error(`Speedtest executable not found after extraction: ${SPEEDTEST_PATH}`);
291 }
292
293 await execAsync(`chmod +x "${SPEEDTEST_PATH}"`);
294 console.log(`Set executable permissions for: ${SPEEDTEST_PATH}`);
295 } else if (platform === "win32") {
296 // Windows 需要解压 zip 文件
297 console.log(`Extracting zip file: ${tempFile}`);
298 const AdmZip = require("adm-zip");
299 const zip = new AdmZip(tempFile);
300 zip.extractAllTo(ASSETS_DIR, true);

Callers 5

autoFixSpeedtestFunction · 0.70
runSpeedtestFunction · 0.70
getAllServersFunction · 0.70
quickPingTestFunction · 0.70
speedtestFunction · 0.70

Calls 4

warnMethod · 0.80
errorMethod · 0.80
ensureDirectoriesFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected