Skip to content

Commit

Permalink
Implement an upload progress estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
JammingBen committed Jun 3, 2022
1 parent 3d2096a commit 27bd671
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/web-runtime/src/components/UploadInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@ export default {
totalProgress: 0, // current uploads progress (0-100)
uploadsPaused: false, // all uploads paused?
uploadsCancelled: false, // all uploads cancelled?
runningUploads: 0 // all uploads (not files!) that are in progress currently
runningUploads: 0, // all uploads (not files!) that are in progress currently
bytesTotal: 0,
bytesUploaded: 0,
filesInEstimation: [],
estimatedTime: 0
}),
computed: {
...mapGetters(['configuration']),
Expand Down Expand Up @@ -235,6 +239,15 @@ export default {
this.$uppyService.subscribe('progress', (value) => {
this.totalProgress = value
})
this.$uppyService.subscribe('upload-progress', ({ file, progress }) => {
const fileInEstimation = this.filesInEstimation.includes(file.meta.uploadId)
if (!fileInEstimation) {
this.filesInEstimation.push(file.meta.uploadId)
this.bytesTotal += progress.bytesTotal
}
this.bytesUploaded += progress.bytesUploaded
})
this.$uppyService.subscribe('uploadError', (file) => {
if (this.errors.includes(file.meta.uploadId)) {
return
Expand Down
4 changes: 4 additions & 0 deletions packages/web-runtime/src/services/uppyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type UppyServiceTopics =
| 'filesSelected'
| 'progress'
| 'addedForUpload'
| 'upload-progress'

export class UppyService {
uppy: Uppy
Expand Down Expand Up @@ -136,6 +137,9 @@ export class UppyService {
this.uppy.on('progress', (value) => {
this.publish('progress', value)
})
this.uppy.on('upload-progress', (file, progress) => {
this.publish('upload-progress', { file, progress })
})
this.uppy.on('cancel-all', () => {
this.publish('uploadCancelled')
})
Expand Down

0 comments on commit 27bd671

Please sign in to comment.