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

Function quickPingServers

speedtest/speedtest.ts:891–919  ·  view source on GitHub ↗

* 快速ping测试多个服务器

(servers: ServerInfo[], maxServers: number = 5)

Source from the content-addressed store, hash-verified

889 * 快速ping测试多个服务器
890 */
891async function quickPingServers(servers: ServerInfo[], maxServers: number = 5): Promise<ServerInfo[]> {
892 const testPromises = servers.slice(0, maxServers).map(async (server) => {
893 try {
894 const result = await testServerAvailability(server.id);
895 return {
896 ...server,
897 available: result.available,
898 ping: result.ping,
899 error: result.error
900 } as ServerInfo;
901 } catch (error) {
902 return {
903 ...server,
904 available: false,
905 error: 'Test failed'
906 } as ServerInfo;
907 }
908 });
909
910 try {
911 const results = await Promise.all(testPromises);
912 return results
913 .filter(server => server.available === true)
914 .sort((a, b) => (a.ping || 999) - (b.ping || 999));
915 } catch (error) {
916 console.error('Quick ping test failed:', error);
917 return [];
918 }
919}
920
921/**
922 * 智能选择最佳可用服务器 - 简化版本

Callers

nothing calls this directly

Calls 2

testServerAvailabilityFunction · 0.85
errorMethod · 0.80

Tested by

no test coverage detected