Refactor server picker and limit ping requests
This commit is contained in:
@@ -16,6 +16,7 @@ import {
|
||||
} from './gatewayPresence.js';
|
||||
import { createSingboxRuntime } from './singboxRuntime.js';
|
||||
import { tcpPing } from './ping.js';
|
||||
import { checkServerHealth } from './serverHealth.js';
|
||||
import { buildSharedProxyInfo } from './sharedProxy.js';
|
||||
import {
|
||||
buildGatewayConfig,
|
||||
@@ -577,12 +578,12 @@ async function handleApi(req, res) {
|
||||
|
||||
if (req.method === 'POST' && req.url === '/api/servers/ping-all') {
|
||||
const state = stateStore.read();
|
||||
const results = await Promise.all((state.servers || []).map(async (server) => ({
|
||||
id: server.id,
|
||||
tag: server.label,
|
||||
...await tcpPing(server.host, server.port),
|
||||
checkedAt: new Date().toISOString(),
|
||||
})));
|
||||
const { serverIds = [] } = await readBody(req);
|
||||
const requestedIds = new Set(Array.isArray(serverIds) ? serverIds.map(String) : []);
|
||||
const servers = requestedIds.size
|
||||
? (state.servers || []).filter((server) => requestedIds.has(server.id))
|
||||
: state.servers || [];
|
||||
const results = await checkServerHealth(servers, tcpPing);
|
||||
return sendState(res, { results });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user