Skip to content

Commit

Permalink
update UppyFile objects before emitting events (#4928)
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Feb 19, 2024
1 parent 7b492d7 commit a0b7d16
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/@uppy/aws-s3-multipart/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ export default class AwsS3Multipart extends BasePlugin {
#uploadLocalFile (file) {
return new Promise((resolve, reject) => {
const onProgress = (bytesUploaded, bytesTotal) => {
this.uppy.emit('upload-progress', file, {
this.uppy.emit('upload-progress', this.uppy.getFile(file.id), {
uploader: this,
bytesUploaded,
bytesTotal,
Expand Down
4 changes: 2 additions & 2 deletions packages/@uppy/aws-s3/src/MiniXHRUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export default class MiniXHRUpload {
timer.progress()

if (ev.lengthComputable) {
this.uppy.emit('upload-progress', file, {
this.uppy.emit('upload-progress', this.uppy.getFile(file.id), {
uploader: this,
bytesUploaded: ev.loaded,
bytesTotal: ev.total,
Expand Down Expand Up @@ -162,7 +162,7 @@ export default class MiniXHRUpload {
uploadURL,
}

this.uppy.emit('upload-success', file, uploadResp)
this.uppy.emit('upload-success', this.uppy.getFile(file.id), uploadResp)

if (uploadURL) {
this.uppy.log(`Download ${file.name} from ${uploadURL}`)
Expand Down
20 changes: 14 additions & 6 deletions packages/@uppy/companion-client/src/RequestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,15 +481,23 @@ export default class RequestClient<M extends Meta, B extends Body> {

switch (action) {
case 'progress': {
emitSocketProgress(this, payload, file)
emitSocketProgress(
this,
payload,
this.uppy.getFile(file.id),
)
break
}
case 'success': {
// @ts-expect-error event expects a lot more data.
// TODO: add missing data?
this.uppy.emit('upload-success', file, {
uploadURL: payload.url,
})
this.uppy.emit(
'upload-success',
this.uppy.getFile(file.id),
// @ts-expect-error event expects a lot more data.
// TODO: add missing data?
{
uploadURL: payload.url,
},
)
socketAbortController?.abort?.()
resolve()
break
Expand Down
4 changes: 2 additions & 2 deletions packages/@uppy/tus/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ export default class Tus<M extends Meta, B extends Body> extends BasePlugin<
if (typeof opts.onProgress === 'function') {
opts.onProgress(bytesUploaded, bytesTotal)
}
this.uppy.emit('upload-progress', file, {
this.uppy.emit('upload-progress', this.uppy.getFile(file.id), {
// TODO: remove `uploader` in next major
// @ts-expect-error untyped
uploader: this,
Expand All @@ -331,7 +331,7 @@ export default class Tus<M extends Meta, B extends Body> extends BasePlugin<
this.resetUploaderReferences(file.id)
queuedRequest.done()

this.uppy.emit('upload-success', file, uploadResp)
this.uppy.emit('upload-success', this.uppy.getFile(file.id), uploadResp)

if (upload.url) {
// @ts-expect-error not typed in tus-js-client
Expand Down
16 changes: 12 additions & 4 deletions packages/@uppy/xhr-upload/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ export default class XHRUpload<
timer.progress()

if (ev.lengthComputable) {
this.uppy.emit('upload-progress', file, {
this.uppy.emit('upload-progress', this.uppy.getFile(file.id), {
// TODO: do not send `uploader` in next major
// @ts-expect-error we can't type this and we should remove it
uploader: this,
Expand Down Expand Up @@ -354,7 +354,11 @@ export default class XHRUpload<
uploadURL,
}

this.uppy.emit('upload-success', file, uploadResp)
this.uppy.emit(
'upload-success',
this.uppy.getFile(file.id),
uploadResp,
)

if (uploadURL) {
this.uppy.log(`Download ${file.name} from ${uploadURL}`)
Expand Down Expand Up @@ -475,7 +479,7 @@ export default class XHRUpload<
if (!ev.lengthComputable) return

files.forEach((file) => {
this.uppy.emit('upload-progress', file, {
this.uppy.emit('upload-progress', this.uppy.getFile(file.id), {
// TODO: do not send `uploader` in next major
// @ts-expect-error we can't type this and we should remove it
uploader: this,
Expand All @@ -496,7 +500,11 @@ export default class XHRUpload<
body,
}
files.forEach((file) => {
this.uppy.emit('upload-success', file, uploadResp)
this.uppy.emit(
'upload-success',
this.uppy.getFile(file.id),
uploadResp,
)
})
return resolve()
}
Expand Down

0 comments on commit a0b7d16

Please sign in to comment.