2022-05-23 19:59:05 -04:00
|
|
|
const SIZE_UNITS = [
|
2022-05-03 16:28:43 -04:00
|
|
|
{ name: 'GB', size: Math.pow(10, 9) },
|
|
|
|
{ name: 'MB', size: Math.pow(10, 6) },
|
|
|
|
{ name: 'KB', size: Math.pow(10, 3) },
|
2022-04-27 23:52:45 -04:00
|
|
|
];
|
|
|
|
|
|
|
|
function displaySize(bytes) {
|
2022-05-23 19:59:05 -04:00
|
|
|
for (const unit of SIZE_UNITS) {
|
2022-04-27 23:52:45 -04:00
|
|
|
if (bytes >= unit.size) {
|
|
|
|
return `${(bytes / unit.size).toFixed(1)}${unit.name}`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return `${bytes}B`;
|
|
|
|
}
|
2022-05-23 19:59:05 -04:00
|
|
|
|
|
|
|
const TIME_UNITS = [
|
|
|
|
{ name: 'd', size: 86400 },
|
|
|
|
{ name: 'h', size: 3600 },
|
|
|
|
{ name: 'm', size: 60 },
|
|
|
|
{ name: 's', size: 1 },
|
|
|
|
];
|
|
|
|
|
|
|
|
function displayTime(seconds) {
|
|
|
|
let result = "";
|
|
|
|
for (const unit of TIME_UNITS) {
|
|
|
|
if (seconds >= unit.size || result !== "") {
|
|
|
|
result += `${Math.floor(seconds / unit.size)}${unit.name}`;
|
|
|
|
seconds = seconds % unit.size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (result === "") {
|
|
|
|
result = "0s";
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|