Finished estimated upload time calculator
This commit is contained in:
parent
ab16fd1c5d
commit
7ae97b1aa3
@ -29,6 +29,8 @@ export class UploadComponent {
|
|||||||
uploadProgress = 0;
|
uploadProgress = 0;
|
||||||
uploadFinished = false;
|
uploadFinished = false;
|
||||||
|
|
||||||
|
uploadSpeedBps: number = 0;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.uploadSpeedTest();
|
this.uploadSpeedTest();
|
||||||
}
|
}
|
||||||
@ -68,6 +70,8 @@ export class UploadComponent {
|
|||||||
console.log(`Uploading file: ${this.fileToUpload.name}, Short storage: ${this.shortStorage}, Single download: ${this.singleDownload}, Password protected: ${this.passwordProtected}`);
|
console.log(`Uploading file: ${this.fileToUpload.name}, Short storage: ${this.shortStorage}, Single download: ${this.singleDownload}, Password protected: ${this.passwordProtected}`);
|
||||||
this.uploadStarted = true;
|
this.uploadStarted = true;
|
||||||
|
|
||||||
|
this.calculateEstimatedUploadTime();
|
||||||
|
|
||||||
|
|
||||||
const interval = setInterval(() => {
|
const interval = setInterval(() => {
|
||||||
if (this.uploadProgress < 100) {
|
if (this.uploadProgress < 100) {
|
||||||
@ -107,28 +111,20 @@ export class UploadComponent {
|
|||||||
const end = new Date().getTime(); // End timer
|
const end = new Date().getTime(); // End timer
|
||||||
const duration = (end - start) / 1000; // Convert ms to seconds
|
const duration = (end - start) / 1000; // Convert ms to seconds
|
||||||
const bitsUploaded = payload.byteLength * 8;
|
const bitsUploaded = payload.byteLength * 8;
|
||||||
const speedBps = bitsUploaded / duration;
|
this.uploadSpeedBps = bitsUploaded / duration;
|
||||||
const speedKbps = speedBps / 1024;
|
console.log("Speed test ping finished.");
|
||||||
const speedMbps = speedKbps / 1024;
|
|
||||||
console.log(`Upload speed: ${speedMbps.toFixed(2)} Mbps`);
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('Error during upload test:', error);
|
console.error('Error during upload test:', error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private calculateEstimatedUploadTime() : void {
|
||||||
* Calculates the estimated upload time.
|
const fileSize = this.fileToUpload?.size;
|
||||||
* @param {number} fileSize - The size of the file in bytes.
|
const uploadSpeed = this.uploadSpeedBps / 8; // Convert bits per second to bytes per second
|
||||||
* @param {number} uploadSpeed - The upload speed in bytes per second.
|
if (fileSize && uploadSpeed) {
|
||||||
* @returns {number} The estimated upload time in seconds.
|
|
||||||
*/
|
|
||||||
private calculateEstimatedUploadTime(fileSize: number, uploadSpeed: number) {
|
|
||||||
if (uploadSpeed <= 0) {
|
|
||||||
console.error("Upload speed must be greater than 0.");
|
|
||||||
return NaN;
|
|
||||||
}
|
|
||||||
const estimatedTimeInSeconds = fileSize / uploadSpeed;
|
const estimatedTimeInSeconds = fileSize / uploadSpeed;
|
||||||
return estimatedTimeInSeconds;
|
console.log(`Estimated upload time: ${estimatedTimeInSeconds} seconds`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user