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

Function queryBest

ntp/ntp.ts:150–167  ·  view source on GitHub ↗
(servers = NTP_SERVERS, timeoutMs = 2500)

Source from the content-addressed store, hash-verified

148 const results = await Promise.all(tasks);
149 const fulfilled = results.filter((r) => r.status === "fulfilled") as Array<{
150 status: "fulfilled";
151 value: NtpResult;
152 }>;
153 if (fulfilled.length === 0) {
154 const firstErr = (results.find((r) => r.status === "rejected") as any)?.reason;
155 throw firstErr || new Error("All NTP queries failed");
156 }
157 // Prefer the one with smallest delay
158 fulfilled.sort((a, b) => (a.value.delayMs ?? 1e12) - (b.value.delayMs ?? 1e12));
159 return fulfilled[0].value;
160}
161
162function fmtMs(ms?: number): string {
163 if (typeof ms !== "number" || !Number.isFinite(ms)) return "-";
164 const sign = ms >= 0 ? "+" : "-";
165 const abs = Math.abs(ms);
166 if (abs >= 1000) return `${sign}${(abs / 1000).toFixed(3)}s`;
167 return `${sign}${abs.toFixed(1)}ms`;
168}
169
170function formatDateCN(date: Date): string {

Callers 1

NtpPluginClass · 0.85

Calls 1

queryOnceFunction · 0.85

Tested by

no test coverage detected