display upload speed and ETA
This commit is contained in:
parent
8f00eb27e2
commit
8b5e9b76bb
2 changed files with 53 additions and 3 deletions
|
@ -1,14 +1,35 @@
|
|||
const UNITS = [
|
||||
const SIZE_UNITS = [
|
||||
{ name: 'GB', size: Math.pow(10, 9) },
|
||||
{ name: 'MB', size: Math.pow(10, 6) },
|
||||
{ name: 'KB', size: Math.pow(10, 3) },
|
||||
];
|
||||
|
||||
function displaySize(bytes) {
|
||||
for (const unit of UNITS) {
|
||||
for (const unit of SIZE_UNITS) {
|
||||
if (bytes >= unit.size) {
|
||||
return `${(bytes / unit.size).toFixed(1)}${unit.name}`;
|
||||
}
|
||||
}
|
||||
return `${bytes}B`;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue