Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transloadit: Emit assembly progress events #4603

Merged
merged 7 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/@uppy/transloadit/src/Assembly.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ class TransloaditAssembly extends Emitter {
;(this.status.results[stepName] ??= []).push(result)
})

this.#sse.addEventListener('assembly_execution_progress', (e) => {
const details = JSON.parse(e.data)
this.emit('execution-progress', details)
})

this.#sse.addEventListener('assembly_error', (e) => {
try {
this.#onError(JSON.parse(e.data))
Expand Down
23 changes: 23 additions & 0 deletions packages/@uppy/transloadit/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,29 @@ export default class Transloadit extends BasePlugin {
this.uppy.emit('transloadit:assembly-executing', assembly.status)
})

assembly.on('execution-progress', (details) => {
this.uppy.emit('transloadit:execution-progress', details)

if (details.progress_combined != null) {
// TODO: Transloadit emits progress information for the entire Assembly combined
// (progress_combined) and for each imported/uploaded file (progress_per_original_file).
// Uppy's current design requires progress to be set for each file, which is then
// averaged to get the total progress (see calculateProcessingProgress.js).
// Therefore, we currently set the combined progres for every file, so that this is
// the same value that is displayed to the end user, although we have more accurate
// per-file progress as well. We cannot use this here or otherwise progress from
// imported files would not be counted towards the total progress because imported
// files are not registered with Uppy.
for (const file of this.uppy.getFiles()) {
this.uppy.emit('postprocess-progress', file, {
mode: 'determinate',
value: details.progress_combined / 100,
message: this.i18n('encoding'),
})
}
}
})

if (this.opts.waitForEncoding) {
assembly.on('result', (stepName, result) => {
this.#onResult(id, stepName, result)
Expand Down