mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-31 07:11:33 +00:00
Improved descriptive upload progress again
Bumped v1 version string
This commit is contained in:
parent
c4c45a5857
commit
df1e835272
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
@ -341,36 +341,45 @@ page.prepareDropzone = () => {
|
||||
if (page.uploadAge !== null) xhr.setRequestHeader('age', page.uploadAge)
|
||||
}
|
||||
|
||||
if (file.upload.chunked)
|
||||
file.previewElement.querySelector('.descriptive-progress').innerHTML =
|
||||
`Uploading chunk ${file.upload.chunks.length}/${file.upload.totalChunkCount}\u2026${file._percentage ? ` ${file._percentage}%` : ''}`
|
||||
else
|
||||
if (!file.upload.chunked)
|
||||
file.previewElement.querySelector('.descriptive-progress').innerHTML = 'Uploading\u2026'
|
||||
else if (file.upload.chunks.length === 1)
|
||||
file.previewElement.querySelector('.descriptive-progress').innerHTML = `Uploading chunk 1/${file.upload.totalChunkCount}\u2026`
|
||||
})
|
||||
|
||||
// Update descriptive progress
|
||||
this.on('uploadprogress', (file, progress) => {
|
||||
// Total bytes will eventually be bigger than file size when chunked
|
||||
const total = Math.max(file.size, file.upload.total)
|
||||
file._percentage = (file.upload.bytesSent / total * 100).toFixed(0)
|
||||
|
||||
const prefix = file.upload.chunked
|
||||
? `Uploading chunk ${file.upload.chunks.length}/${file.upload.totalChunkCount}\u2026`
|
||||
: 'Uploading\u2026'
|
||||
const percentage = (file.upload.bytesSent / total * 100).toFixed(0)
|
||||
|
||||
const upl = file.upload.chunked
|
||||
? file.upload.chunks[file.upload.chunks.length - 1]
|
||||
: file.upload
|
||||
const xhr = upl.xhr || file.xhr
|
||||
|
||||
const bytesSent = upl.bytesSent
|
||||
const elapsed = (Date.now() - xhr._start) / 1000
|
||||
let prefix = 'Uploading\u2026'
|
||||
let skipProgress = false
|
||||
if (file.upload.chunked) {
|
||||
const done = upl.bytesSent === upl.total
|
||||
const last = file.upload.chunks.length === file.upload.totalChunkCount
|
||||
let chunkIndex = file.upload.chunks.length
|
||||
if (done && !last) {
|
||||
chunkIndex++
|
||||
skipProgress = true
|
||||
}
|
||||
prefix = `Uploading chunk ${chunkIndex}/${file.upload.totalChunkCount}\u2026`
|
||||
}
|
||||
|
||||
const bytesPerSec = elapsed ? (bytesSent / elapsed) : 0
|
||||
const prettyBytesPerSec = page.getPrettyBytes(bytesPerSec)
|
||||
let prettyBytesPerSec
|
||||
if (!skipProgress) {
|
||||
const elapsed = (Date.now() - xhr._start) / 1000
|
||||
const bytesPerSec = elapsed ? (upl.bytesSent / elapsed) : 0
|
||||
prettyBytesPerSec = page.getPrettyBytes(bytesPerSec)
|
||||
}
|
||||
|
||||
file.previewElement.querySelector('.descriptive-progress').innerHTML =
|
||||
`${prefix} ${file._percentage}%${prettyBytesPerSec ? ` at ~${prettyBytesPerSec}/s` : ''}`
|
||||
`${prefix} ${percentage}%${prettyBytesPerSec ? ` at ~${prettyBytesPerSec}/s` : ''}`
|
||||
})
|
||||
|
||||
this.on('success', (file, response) => {
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"1": "1574788369",
|
||||
"1": "1574791009",
|
||||
"2": "1568894058",
|
||||
"3": "1568894058",
|
||||
"4": "1568894058",
|
||||
|
Loading…
Reference in New Issue
Block a user