mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 10:34:17 +00:00
- Introduces a new Music Library system for managing favorites (tracks, playlists, releases), replacing the previous TrackLike model. - Completely revamps the Studio TV profile page, adding live statistics, stream configuration, restream management, and media URL display. - Enhances the media player with a custom seekbar and improved audio playback logic for MPD and non-MPD sources. - Lays foundational groundwork for chat encryption with new models and APIs. - Refactors critical UI components like PlaylistView and PagePanel. - Standardizes monorepo development scripts to use npm. - Updates comty.js submodule and adds various new UI components.
39 lines
911 B
JavaScript
39 lines
911 B
JavaScript
export const formatBytes = (bytes, decimals = 2) => {
|
|
if (
|
|
bytes === undefined ||
|
|
bytes === null ||
|
|
isNaN(parseFloat(bytes)) ||
|
|
!isFinite(bytes)
|
|
)
|
|
return "0 Bytes"
|
|
if (bytes === 0) {
|
|
return "0 Bytes"
|
|
}
|
|
|
|
const k = 1024
|
|
const dm = decimals < 0 ? 0 : decimals
|
|
const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]
|
|
|
|
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
|
|
|
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i]
|
|
}
|
|
|
|
export const formatBitrate = (bytesPerSecond) => {
|
|
if (typeof bytesPerSecond !== "number" || isNaN(bytesPerSecond)) {
|
|
return "0 Kbps"
|
|
}
|
|
|
|
const bitsPerSecond = bytesPerSecond * 8
|
|
|
|
if (bitsPerSecond >= 1000000) {
|
|
return `${(bitsPerSecond / 1000000).toFixed(1)} Mbps`
|
|
}
|
|
|
|
if (bitsPerSecond >= 1000 || bitsPerSecond === 0) {
|
|
return `${(bitsPerSecond / 1000).toFixed(0)} Kbps`
|
|
}
|
|
|
|
return `${bitsPerSecond.toFixed(0)} bps`
|
|
}
|