Updated home.js again: Fixed live upload speed

My silly bad habit of not debugging things properly before committing
This commit is contained in:
Bobby Wibowo 2020-04-21 17:27:10 +07:00
parent f27db6f252
commit 9c7b0e22d7
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF
4 changed files with 11 additions and 7 deletions

2
dist/js/home.js vendored

File diff suppressed because one or more lines are too long

2
dist/js/home.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -385,22 +385,26 @@ page.prepareDropzone = () => {
}
// Upload speed calculation
let bytesPerSec
let prettyBytesPerSec
if (!skipProgress) {
const now = Date.now()
const elapsedSecs = (now - xhr._upSpeedCalc.timestamp) / 1000
// Calculate only if at least 1 second has elapsed
// Calculate only if at least 1s has elapsed
if (elapsedSecs >= 1) {
const bytesSent = upl.bytesSent - xhr._upSpeedCalc.bytes
bytesPerSec = elapsedSecs ? (bytesSent / elapsedSecs) : 0
const bytesPerSec = elapsedSecs ? (bytesSent / elapsedSecs) : 0
// Update data for next upload speed calculation
xhr._upSpeedCalc.bytes = upl.bytesSent
xhr._upSpeedCalc.timestamp = now
// Store latest pretty speed to be used in next iteration, if less than 1s elapsed
xhr._upSpeedCalc.lastPretty = prettyBytesPerSec = page.getPrettyBytes(bytesPerSec)
} else if (xhr._upSpeedCalc.lastPretty) {
prettyBytesPerSec = xhr._upSpeedCalc.lastPretty
}
}
file.previewElement.querySelector('.descriptive-progress').innerHTML =
`${prefix} ${percentage}%${bytesPerSec ? ` at ${page.getPrettyBytes(bytesPerSec)}/s` : ''}`
`${prefix} ${percentage}%${prettyBytesPerSec ? ` at ${prettyBytesPerSec}/s` : ''}`
})
this.on('success', (file, data) => {

View File

@ -1,5 +1,5 @@
{
"1": "1587464170",
"1": "1587464783",
"2": "1581416390",
"3": "1581416390",
"4": "1581416390",