mirror of
https://github.com/h44z/wg-portal.git
synced 2025-10-05 16:06:17 +00:00
* Added peers sorting for Interface and Profile views * Use ip-address package to sort with IPv6 addresses only * Add RX/TX column and fix add-peer button title
21 lines
583 B
JavaScript
21 lines
583 B
JavaScript
import { Address4, Address6 } from "ip-address"
|
|
|
|
export function ipToBigInt(ip) {
|
|
// Check if it's an IPv4 address
|
|
if (ip.includes(".")) {
|
|
const addr = new Address4(ip)
|
|
return addr.bigInteger()
|
|
}
|
|
|
|
// Otherwise, assume it's an IPv6 address
|
|
const addr = new Address6(ip)
|
|
return addr.bigInteger()
|
|
}
|
|
|
|
export function humanFileSize(size) {
|
|
const sizes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]
|
|
if (size === 0) return "0B"
|
|
const i = parseInt(Math.floor(Math.log(size) / Math.log(1024)))
|
|
return Math.round(size / Math.pow(1024, i), 2) + sizes[i]
|
|
}
|