mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-02-22 13:19:05 +00:00
Updated home.js: Live upload speed
Previously it calculated average upload speed instead This should be more accurate/reliable
This commit is contained in:
parent
3b1779e492
commit
7cd9e5b40b
2
dist/js/home.js
vendored
2
dist/js/home.js
vendored
File diff suppressed because one or more lines are too long
2
dist/js/home.js.map
vendored
2
dist/js/home.js.map
vendored
File diff suppressed because one or more lines are too long
@ -339,9 +339,12 @@ page.prepareDropzone = () => {
|
|||||||
page.dropzone._handleUploadError(instances, xhr, 'Connection timed out. Try to reduce upload chunk size.')
|
page.dropzone._handleUploadError(instances, xhr, 'Connection timed out. Try to reduce upload chunk size.')
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add start timestamp of upload attempt
|
// Attach necessary data for initial upload speed calculation
|
||||||
if (xhr._start === undefined)
|
if (xhr._upSpeedCalc === undefined)
|
||||||
xhr._start = Date.now()
|
xhr._upSpeedCalc = {
|
||||||
|
bytes: 0,
|
||||||
|
timestamp: Date.now()
|
||||||
|
}
|
||||||
|
|
||||||
// If not chunked uploads, add extra headers
|
// If not chunked uploads, add extra headers
|
||||||
if (!file.upload.chunked) {
|
if (!file.upload.chunked) {
|
||||||
@ -381,15 +384,21 @@ page.prepareDropzone = () => {
|
|||||||
prefix = `Uploading chunk ${chunkIndex}/${file.upload.totalChunkCount}\u2026`
|
prefix = `Uploading chunk ${chunkIndex}/${file.upload.totalChunkCount}\u2026`
|
||||||
}
|
}
|
||||||
|
|
||||||
let prettyBytesPerSec
|
// Upload speed calculation
|
||||||
|
let bytesPerSec
|
||||||
if (!skipProgress) {
|
if (!skipProgress) {
|
||||||
const elapsed = (Date.now() - xhr._start) / 1000
|
const now = Date.now()
|
||||||
const bytesPerSec = elapsed ? (upl.bytesSent / elapsed) : 0
|
const elapsedSecs = (now - xhr._upSpeedCalc.timestamp) / 1000
|
||||||
prettyBytesPerSec = page.getPrettyBytes(bytesPerSec)
|
const bytesSent = upl.bytesSent - xhr._upSpeedCalc.bytes
|
||||||
|
bytesPerSec = elapsedSecs ? (bytesSent / elapsedSecs) : 0
|
||||||
|
|
||||||
|
// Update data for next upload speed calculation
|
||||||
|
xhr._upSpeedCalc.bytes = upl.bytesSent
|
||||||
|
xhr._upSpeedCalc.timestamp = now
|
||||||
}
|
}
|
||||||
|
|
||||||
file.previewElement.querySelector('.descriptive-progress').innerHTML =
|
file.previewElement.querySelector('.descriptive-progress').innerHTML =
|
||||||
`${prefix} ${percentage}%${prettyBytesPerSec ? ` at ~${prettyBytesPerSec}/s` : ''}`
|
`${prefix} ${percentage}%${bytesPerSec ? ` at ${page.getPrettyBytes(bytesPerSec)}/s` : ''}`
|
||||||
})
|
})
|
||||||
|
|
||||||
this.on('success', (file, data) => {
|
this.on('success', (file, data) => {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"1": "1587322292",
|
"1": "1587463408",
|
||||||
"2": "1581416390",
|
"2": "1581416390",
|
||||||
"3": "1581416390",
|
"3": "1581416390",
|
||||||
"4": "1581416390",
|
"4": "1581416390",
|
||||||
|
Loading…
Reference in New Issue
Block a user