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

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