| 352 | let value = bytes; |
| 353 | let unitIndex = 0; |
| 354 | |
| 355 | const units = isBytes |
| 356 | ? ["B", "KB", "MB", "GB", "TB"] |
| 357 | : ["bps", "Kbps", "Mbps", "Gbps", "Tbps"]; |
| 358 | |
| 359 | if (!isBytes) { |
| 360 | value *= 8; // Convert bytes to bits |
| 361 | } |
| 362 | |
| 363 | while (value >= power && unitIndex < units.length - 1) { |
| 364 | value /= power; |
| 365 | unitIndex++; |
| 366 | } |
| 367 | |
| 368 | return `${Math.round(value * 100) / 100}${units[unitIndex]}`; |
| 369 | } |
| 370 | |
| 371 | async function getIpApi(ip: string): Promise<{ |
| 372 | asInfo: string; |
| 373 | ccName: string; |
| 374 | ccCode: string; |
| 375 | ccFlag: string; |
| 376 | ccLink: string; |
| 377 | }> { |
| 378 | try { |
| 379 | const response = await axios.get( |