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

update UppyFile objects before emitting events #4928

Merged
merged 2 commits into from
Feb 19, 2024
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
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
Loading