mirror of
https://github.com/h44z/wg-portal.git
synced 2025-09-15 15:21:14 +00:00
feat: Added peers sorting on views (#302)
* 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
This commit is contained in:
20
frontend/src/helpers/utils.js
Normal file
20
frontend/src/helpers/utils.js
Normal file
@@ -0,0 +1,20 @@
|
||||
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]
|
||||
}
|
Reference in New Issue
Block a user