pingdotgg / uploadthing

File uploads for modern web devs
https://uploadthing.com
MIT License
4.26k stars 315 forks source link

feat: forward request context to `onUploadComplete` and `onUploadError` #1045

Closed juliusmarminge closed 2 weeks ago

juliusmarminge commented 2 weeks ago

currently you can only access the request in middleware. This adds so you can also access it in onUploadComplete and onUploadError. This is especially important in e.g. workers where your environment variables and bindings are on the request context

Summary by CodeRabbit

Release Notes

changeset-bot[bot] commented 2 weeks ago

πŸ¦‹ Changeset detected

Latest commit: 9f3d8d92c60e606c937453f41c418282852a46c3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ----------- | ----- | | uploadthing | Minor |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

vercel[bot] commented 2 weeks ago

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated (UTC)
docs-uploadthing βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Nov 6, 2024 9:09am
1 Skipped Deployment | Name | Status | Preview | Comments | Updated (UTC) | | :--- | :----- | :------ | :------- | :------ | | **legacy-docs-uploadthing** | ⬜️ Ignored ([Inspect](https://vercel.com/pinglabs/legacy-docs-uploadthing/GzbSXTfsvKVubYLx3HrjrYBZZz5v)) | [Visit Preview](https://legacy-docs-uploadthing-git-forward-request-args-to-cb-pinglabs.vercel.app) | | Nov 6, 2024 9:09am |
coderabbitai[bot] commented 2 weeks ago

Walkthrough

The changes introduce a new feature that forwards the request context to the onUploadComplete and onUploadError callbacks, allowing access to relevant upload information. Additionally, the type MiddlewareArgs has been renamed to AdapterArgs across various files, reflecting a shift in the argument structure. The onUploadComplete method's parameters have been updated to destructured parameters, improving clarity in handling metadata and file information. The modifications also refine type definitions, enhance error handling, and improve test coverage.

Changes

File Change Summary
.changeset/warm-moons-count.md Introduced request context forwarding to onUploadComplete and onUploadError callbacks.
examples/backend-adapters/server/src/router.ts Updated onUploadComplete method parameters from data to destructured { metadata, file }.
packages/uploadthing/src/effect-platform.ts Updated import from MiddlewareArguments to AdapterArguments and adjusted internal logic accordingly.
packages/uploadthing/src/express.ts Renamed MiddlewareArgs to AdapterArgs, updated createUploadthing function to use new type.
packages/uploadthing/src/fastify.ts Renamed MiddlewareArgs to AdapterArgs, updated createUploadthing function to use new type.
packages/uploadthing/src/h3.ts Renamed MiddlewareArgs to AdapterArgs, updated createUploadthing function to use new type.
packages/uploadthing/src/internal/handler.ts Renamed MiddlewareArguments to AdapterArguments, updated related types and imports.
packages/uploadthing/src/internal/types.ts Renamed MiddlewareFnArgs to AdapterFnArgs, updated related type references.
packages/uploadthing/src/internal/upload-builder.ts Replaced TMiddlewareArgs with TAdapterFnArgs in createBuilder and internalCreateBuilder functions.
packages/uploadthing/src/next-legacy.ts Renamed MiddlewareArgs to AdapterArgs, updated createUploadthing function to use new type.
packages/uploadthing/src/next.ts Renamed MiddlewareArgs to AdapterArgs, updated createUploadthing function to use new type.
packages/uploadthing/src/remix.ts Renamed MiddlewareArgs to AdapterArgs, updated createUploadthing function to use new type.
packages/uploadthing/src/server.ts Renamed MiddlewareArgs to AdapterArgs, updated createUploadthing function to use new type.
packages/uploadthing/test/request-handler.test.ts Enhanced tests for error handling, middleware functionality, input validation, and file upload logic.

Possibly related PRs

Suggested labels

sdk

Suggested reviewers

Poem

In a world of uploads, swift and bright,
We forward our context, a new delight.
With metadata in hand, we log with glee,
Adapters now dance, as happy as can be!
So let’s celebrate this change, oh so grand,
A hop and a skip, in code we stand! πŸ‡βœ¨


πŸ“œ Recent review details **Configuration used: CodeRabbit UI** **Review profile: CHILL**
πŸ“₯ Commits Reviewing files that changed from the base of the PR and between 55df5bf27aea46581b70df964b774d278b4e1656 and 9f3d8d92c60e606c937453f41c418282852a46c3.
πŸ“’ Files selected for processing (1) * `packages/uploadthing/src/effect-platform.ts` (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1) * packages/uploadthing/src/effect-platform.ts

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❀️ Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
πŸͺ§ Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit , please review it.` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` - `@coderabbitai help me debug CodeRabbit configuration file.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (Invoked using PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai full review` to do a full review from scratch and review all the files again. - `@coderabbitai summary` to regenerate the summary of the PR. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. ### Other keywords and placeholders - Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. - Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description. - Add `@coderabbitai` anywhere in the PR title to generate the title automatically. ### CodeRabbit Configuration File (`.coderabbit.yaml`) - You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository. - Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information. - If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json` ### Documentation and Community - Visit our [Documentation](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
pkg-pr-new[bot] commented 2 weeks ago

Open in Stackblitz

More templates

- [@example/minimal-appdir](https://pkg.pr.new/template/4fbbb089-7b42-4fd8-a45c-1634645b434a) - [@example/minimal-astro-react](https://pkg.pr.new/template/c13b003d-791c-4b82-a1d2-f246670a520c) - [@example/minimal-expo](https://pkg.pr.new/template/f8efd348-8e67-436f-a27b-556bcdaa242c) - [@example/minimal-nuxt](https://pkg.pr.new/template/1a71569f-9182-4cb3-a329-4a32bb709c51) - [@example/minimal-pagedir](https://pkg.pr.new/template/d8c58f34-2c70-42e5-9e19-41ed6d760034) - [@example/minimal-solidstart](https://pkg.pr.new/template/52d72009-3150-45b3-96e7-5d642aeb0631) - [@example/minimal-sveltekit](https://pkg.pr.new/template/9aa8629a-ee71-45ea-a4f7-f5fb7855f5a1) - [@example/minimal-tanstack-start](https://pkg.pr.new/template/88fd7bed-0cb8-453e-afed-451586bc4cbd)

pnpm add https://pkg.pr.new/pingdotgg/uploadthing@1045

commit: 9f3d8d9

github-actions[bot] commented 2 weeks ago

πŸ“¦ Bundle size comparison

Bundle Size (gzip) Visualization
Main 27.51KB See Treemap πŸ“Š
PR (94c5a521683712bd43c06eab96d5493da9c28d28) 27.51KB See Treemap πŸ“Š
Diff No change