feat(upload): improve speed display formatting

This commit is contained in:
ArielLeyva 2025-09-24 22:06:57 -04:00 committed by Henrique Dias
parent 9df7979110
commit e8e40abb0c
No known key found for this signature in database

View File

@ -14,7 +14,7 @@
}}
</h2>
<div class="upload-info">
<div class="upload-speed">{{ speedMbytes }}/s</div>
<div class="upload-speed">{{ speedText }}/s</div>
<div class="upload-eta">{{ formattedETA }} remaining</div>
<div class="upload-percentage">{{ sentPercent }}% Completed</div>
<div class="upload-fraction">
@ -88,6 +88,7 @@ const uploadStore = useUploadStore();
const { sentBytes, totalBytes } = storeToRefs(uploadStore);
const byteToMbyte = partial({ exponent: 2 });
const byteToKbyte = partial({ exponent: 1 });
const sentPercent = computed(() =>
((uploadStore.sentBytes / uploadStore.totalBytes) * 100).toFixed(2)
@ -95,7 +96,17 @@ const sentPercent = computed(() =>
const sentMbytes = computed(() => byteToMbyte(uploadStore.sentBytes));
const totalMbytes = computed(() => byteToMbyte(uploadStore.totalBytes));
const speedMbytes = computed(() => byteToMbyte(speed.value));
const speedText = computed(() => {
const bytes = speed.value;
if (bytes < 1024 * 1024) {
const kb = parseFloat(byteToKbyte(bytes));
return `${kb.toFixed(2)} KB`;
} else {
const mb = parseFloat(byteToMbyte(bytes));
return `${mb.toFixed(2)} MB`;
}
});
let lastSpeedUpdate: number = 0;
let recentSpeeds: number[] = [];