MCPcopy Index your code
hub / github.com/TeleBoxOrg/TeleBox_Plugins / diagnoseSpeedtestExecutable

Function diagnoseSpeedtestExecutable

speedtest/speedtest.ts:451–495  ·  view source on GitHub ↗

* 诊断speedtest可执行文件问题

()

Source from the content-addressed store, hash-verified

449 * 诊断speedtest可执行文件问题
450 */
451async function diagnoseSpeedtestExecutable(): Promise<{ canRun: boolean; error?: string; needsReinstall: boolean }> {
452 try {
453 // 检查文件是否存在
454 if (!fs.existsSync(SPEEDTEST_PATH)) {
455 return { canRun: false, error: "可执行文件不存在", needsReinstall: true };
456 }
457
458 // 检查文件权限(Unix系统)
459 if (process.platform !== "win32") {
460 try {
461 const stats = fs.statSync(SPEEDTEST_PATH);
462 if (!(stats.mode & parseInt('111', 8))) {
463 console.log("Fixing executable permissions...");
464 await execAsync(`chmod +x "${SPEEDTEST_PATH}"`);
465 }
466 } catch (permError) {
467 return { canRun: false, error: "权限检查失败", needsReinstall: true };
468 }
469 }
470
471 // 尝试运行版本检查
472 try {
473 const { stdout, stderr } = await execAsync(`"${SPEEDTEST_PATH}" --version`, { timeout: 10000 });
474 if (stdout && stdout.includes("Speedtest")) {
475 return { canRun: true, needsReinstall: false };
476 }
477 } catch (versionError) {
478 console.log("Version check failed:", versionError);
479 }
480
481 // 尝试基本帮助命令
482 try {
483 const { stdout, stderr } = await execAsync(`"${SPEEDTEST_PATH}" --help`, { timeout: 10000 });
484 if (stdout && (stdout.includes("Speedtest") || stdout.includes("usage"))) {
485 return { canRun: true, needsReinstall: false };
486 }
487 } catch (helpError) {
488 console.log("Help check failed:", helpError);
489 }
490
491 return { canRun: false, error: "可执行文件无法运行,可能是架构不匹配或文件损坏", needsReinstall: true };
492 } catch (error: any) {
493 return { canRun: false, error: error.message || "诊断失败", needsReinstall: true };
494 }
495}
496
497/**
498 * 自动修复speedtest安装问题

Callers 3

autoFixSpeedtestFunction · 0.85
runSpeedtestFunction · 0.85
speedtestFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected