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

Function unitConvert

speedlink/speedlink.ts:348–361  ·  view source on GitHub ↗
(bytes: number, isBytes: boolean = false)

Source from the content-addressed store, hash-verified

346 const units = isBytes
347 ? ["B", "KB", "MB", "GB", "TB"]
348 : ["bps", "Kbps", "Mbps", "Gbps", "Tbps"];
349 if (!isBytes) value *= 8;
350 while (value >= power && unitIndex < units.length - 1) {
351 value /= power;
352 unitIndex++;
353 }
354 return `${Math.round(value * 100) / 100}${units[unitIndex]}`;
355}
356
357async function getIpApi(ip: string) {
358 try {
359 const response = await axios.get(`http://ip-api.com/json/${ip}?fields=as,countryCode`);
360 const data = response.data;
361 const asInfo = data.as?.split(" ")[0] || "";
362 const ccFlag = data.countryCode
363 ? String.fromCodePoint(
364 ...data.countryCode

Callers 1

speedtestFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected