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

Function selectBestServerWithFallback

speedtest/speedtest.ts:943–968  ·  view source on GitHub ↗

* 备用:选择多个候选服务器进行测试

()

Source from the content-addressed store, hash-verified

941 * 备用:选择多个候选服务器进行测试
942 */
943async function selectBestServerWithFallback(): Promise<number | null> {
944 try {
945 const allServers = await getAllServers();
946 if (allServers.length === 0) {
947 return null;
948 }
949
950 // 尝试前3个服务器,通常按距离排序,成功率更高
951 for (let i = 0; i < Math.min(3, allServers.length); i++) {
952 const serverId = allServers[i].id;
953 try {
954 // 简单验证:检查服务器是否在列表中即认为可用
955 return serverId;
956 } catch (error) {
957 console.log(`Server ${serverId} test failed, trying next...`);
958 continue;
959 }
960 }
961
962 // 如果前3个都有问题,返回第一个作为fallback
963 return allServers[0].id;
964 } catch (error) {
965 console.error('Failed to select best server with fallback:', error);
966 return null;
967 }
968}
969
970async function checkNetworkConnectivity(): Promise<{ connected: boolean; message: string }> {
971 try {

Callers

nothing calls this directly

Calls 2

getAllServersFunction · 0.85
errorMethod · 0.80

Tested by

no test coverage detected