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

Function autoFixSpeedtest

speedtest/speedtest.ts:500–548  ·  view source on GitHub ↗

* 自动修复speedtest安装问题

()

Source from the content-addressed store, hash-verified

498 SPEEDTEST_PATH,
499 path.join(ASSETS_DIR, "speedtest.exe"),
500 path.join(ASSETS_DIR, "speedtest"),
501 ];
502
503 for (const file of filesToClean) {
504 if (fs.existsSync(file)) {
505 try {
506 fs.unlinkSync(file);
507 console.log(`Cleaned up file: ${file}`);
508 } catch (cleanupError) {
509 console.warn(`Failed to cleanup file: ${file}`, cleanupError);
510 }
511 }
512 }
513
514 // 清理临时文件
515 try {
516 const tempFiles = fs.readdirSync(ASSETS_DIR).filter(file =>
517 file.endsWith('.tgz') || file.endsWith('.zip')
518 );
519 for (const tempFile of tempFiles) {
520 try {
521 fs.unlinkSync(path.join(ASSETS_DIR, tempFile));
522 console.log(`Cleaned up temp file: ${tempFile}`);
523 } catch (cleanupError) {
524 console.warn(`Failed to cleanup temp file: ${tempFile}`, cleanupError);
525 }
526 }
527 } catch (readDirError) {
528 console.warn("Failed to read assets directory:", readDirError);
529 }
530
531 // 重新下载
532 await downloadCli();
533
534 // 验证修复结果
535 const diagnosis = await diagnoseSpeedtestExecutable();
536 if (!diagnosis.canRun) {
537 throw new Error(`自动修复失败: ${diagnosis.error}`);
538 }
539
540 console.log("Auto-fix completed successfully");
541}
542
543/**
544 * 使用系统已安装的 speedtest 可执行文件运行测试
545 * 优先尝试 `speedtest`,如果不存在再尝试 `speedtest-cli`
546 */
547async function runSystemSpeedtest(serverId?: number, retryCount: number = 0): Promise<SpeedtestResult> {
548 const MAX_RETRIES = 1;
549 try {
550 // 查找系统可执行文件
551 const candidates = process.platform === 'win32' ? ['speedtest.exe', 'speedtest-cli.exe'] : ['speedtest', 'speedtest-cli'];

Callers 2

runSpeedtestFunction · 0.85
speedtestFunction · 0.85

Calls 3

warnMethod · 0.80
downloadCliFunction · 0.70

Tested by

no test coverage detected