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

@uppy/tus: fix onBeforeRequest type #5566

Merged
merged 1 commit into from
Jan 6, 2025

Conversation

dschmidt
Copy link
Contributor

@dschmidt dschmidt commented Dec 30, 2024

c.f.

let userProvidedPromise
if (typeof onBeforeRequest === 'function') {
userProvidedPromise = onBeforeRequest(req, file)
}
if (hasProperty(queuedRequest, 'shouldBeRequeued')) {
if (!queuedRequest.shouldBeRequeued) return Promise.reject()
// TODO: switch to `Promise.withResolvers` on the next major if available.
let done: () => void
// eslint-disable-next-line promise/param-names
const p = new Promise<void>((res) => {
done = res
})
queuedRequest = this.requests.run(() => {
if (file.isPaused) {
queuedRequest.abort()
}
done()
return () => {}
})
// If the request has been requeued because it was rate limited by the
// remote server, we want to wait for `RateLimitedQueue` to dispatch
// the re-try request.
// Therefore we create a promise that the queue will resolve when
// enough time has elapsed to expect not to be rate-limited again.
// This means we can hold the Tus retry here with a `Promise.all`,
// together with the returned value of the user provided
// `onBeforeRequest` option callback (in case it returns a promise).
await Promise.all([p, userProvidedPromise])

Sonarcloud was complaining because we returned a Promise in our onBeforeRequest handler:
image
owncloud/web#12052 (comment)

Copy link
Contributor

Diff output files
No diff

@dschmidt
Copy link
Contributor Author

No idea, why we have a promise there at all - but the type seems wrong anyhow 😁

Copy link
Member

@Murderlon Murderlon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Murderlon Murderlon changed the title fix(types): tus.onBeforeRequest handler may return a promise @uppy/tus: fix onBeforeRequest type Jan 6, 2025
@Murderlon Murderlon merged commit 982663a into transloadit:main Jan 6, 2025
16 checks passed
@github-actions github-actions bot mentioned this pull request Jan 6, 2025
github-actions bot added a commit that referenced this pull request Jan 6, 2025
| Package                    | Version | Package                    | Version |
| -------------------------- | ------- | -------------------------- | ------- |
| @uppy/audio                |   2.1.0 | @uppy/onedrive             |   4.2.0 |
| @uppy/aws-s3               |   4.2.0 | @uppy/progress-bar         |   4.2.0 |
| @uppy/box                  |   3.2.0 | @uppy/provider-views       |   4.3.0 |
| @uppy/companion-client     |   4.4.0 | @uppy/react                |   4.2.0 |
| @uppy/compressor           |   2.2.0 | @uppy/remote-sources       |   2.3.0 |
| @uppy/core                 |   4.4.0 | @uppy/screen-capture       |   4.2.0 |
| @uppy/dashboard            |   4.3.0 | @uppy/status-bar           |   4.1.0 |
| @uppy/drag-drop            |   4.1.0 | @uppy/store-default        |   4.2.0 |
| @uppy/drop-target          |   3.1.0 | @uppy/svelte               |   4.2.0 |
| @uppy/dropbox              |   4.2.0 | @uppy/thumbnail-generator  |   4.1.0 |
| @uppy/facebook             |   4.2.0 | @uppy/transloadit          |   4.2.0 |
| @uppy/file-input           |   4.1.0 | @uppy/tus                  |   4.2.0 |
| @uppy/form                 |   4.1.0 | @uppy/unsplash             |   4.2.0 |
| @uppy/golden-retriever     |   4.1.0 | @uppy/url                  |   4.2.0 |
| @uppy/google-drive         |   4.3.0 | @uppy/utils                |   6.1.0 |
| @uppy/google-drive-picker  |   0.3.0 | @uppy/vue                  |   2.1.0 |
| @uppy/google-photos        |   0.5.0 | @uppy/webcam               |   4.1.0 |
| @uppy/google-photos-picker |   0.3.0 | @uppy/webdav               |   0.3.0 |
| @uppy/image-editor         |   3.3.0 | @uppy/xhr-upload           |   4.3.0 |
| @uppy/informer             |   4.2.0 | @uppy/zoom                 |   3.2.0 |
| @uppy/instagram            |   4.2.0 | uppy                       |  4.11.0 |
| @uppy/locales              |   4.5.0 |                            |         |

- meta: build(deps): bump docker/metadata-action from 5.5.1 to 5.6.1 (dependabot[bot] / #5525)
- examples,@uppy/svelte: build(deps-dev): bump @sveltejs/kit from 2.5.17 to 2.8.3 (dependabot[bot] / #5526)
- meta: build(deps): bump docker/build-push-action from 6.9.0 to 6.10.0 (dependabot[bot] / #5531)
- meta: build(deps): bump elliptic from 6.5.7 to 6.6.0 (dependabot[bot] / #5498)
- @uppy/utils: Use .js(x) for all imports instead .ts(x) (Merlijn Vos / #5573)
- @uppy/angular,@uppy/audio,@uppy/aws-s3,@uppy/box,@uppy/companion-client,@uppy/compressor,@uppy/core,@uppy/dashboard,@uppy/drag-drop,@uppy/drop-target,@uppy/dropbox,@uppy/facebook,@uppy/file-input,@uppy/form,@uppy/golden-retriever,@uppy/google-drive-picker,@uppy/google-drive,@uppy/google-photos-picker,@uppy/google-photos,@uppy/image-editor,@uppy/informer,@uppy/instagram,@uppy/locales,@uppy/onedrive,@uppy/progress-bar,@uppy/provider-views,@uppy/react,@uppy/remote-sources,@uppy/screen-capture,@uppy/status-bar,@uppy/thumbnail-generator,@uppy/transloadit,@uppy/tus,@uppy/unsplash,@uppy/url,@uppy/vue,@uppy/webcam,@uppy/webdav,@uppy/xhr-upload,@uppy/zoom: Remove "paths" from all tsconfig's (Merlijn Vos / #5572)
- @uppy/tus: fix onBeforeRequest type (Dominik Schmidt / #5566)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants