MCPcopy Index your code
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安装问题
499 */
500async function autoFixSpeedtest(): Promise<void> {
501 console.log("Starting auto-fix for speedtest...");
502
503 // 清理可能损坏的文件
504 const filesToClean = [
505 SPEEDTEST_PATH,
506 path.join(ASSETS_DIR, "speedtest.exe"),
507 path.join(ASSETS_DIR, "speedtest"),
508 ];
509
510 for (const file of filesToClean) {
511 if (fs.existsSync(file)) {
512 try {
513 fs.unlinkSync(file);
514 console.log(`Cleaned up file: ${file}`);
515 } catch (cleanupError) {
516 console.warn(`Failed to cleanup file: ${file}`, cleanupError);
517 }
518 }
519 }
520
521 // 清理临时文件
522 try {
523 const tempFiles = fs.readdirSync(ASSETS_DIR).filter(file =>
524 file.endsWith('.tgz') || file.endsWith('.zip')
525 );
526 for (const tempFile of tempFiles) {
527 try {
528 fs.unlinkSync(path.join(ASSETS_DIR, tempFile));
529 console.log(`Cleaned up temp file: ${tempFile}`);
530 } catch (cleanupError) {
531 console.warn(`Failed to cleanup temp file: ${tempFile}`, cleanupError);
532 }
533 }
534 } catch (readDirError) {
535 console.warn("Failed to read assets directory:", readDirError);
536 }
537
538 // 重新下载
539 await downloadCli();
540
541 // 验证修复结果
542 const diagnosis = await diagnoseSpeedtestExecutable();
543 if (!diagnosis.canRun) {
544 throw new Error(`自动修复失败: ${diagnosis.error}`);
545 }
546
547 console.log("Auto-fix completed successfully");
548}
549
550/**
551 * 使用系统已安装的 speedtest 可执行文件运行测试

Callers 2

runSpeedtestFunction · 0.85
speedtestFunction · 0.85

Calls 3

warnMethod · 0.80
downloadCliFunction · 0.70

Tested by

no test coverage detected