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

feat: enhance upload configuration with additional Uppy and XHRUpload… #553

Merged

Conversation

cycleccc
Copy link
Collaborator

@cycleccc cycleccc commented Mar 2, 2025

… options

  • Add support for passing custom Uppy and XHRUpload configuration options
  • Update IUploadConfig interface to include uppyConfig and xhrConfig
  • Spread additional configuration options in createUploader

Changes Overview

Implementation Approach

Testing Done

Verification Steps

Additional Notes

Checklist

  • I have created a changeset for this PR if necessary.
  • My changes do not break the library.
  • I have added tests where applicable.
  • I have followed the project guidelines.
  • I have fixed any lint issues.

Related Issues

Summary by CodeRabbit

  • New Features
    • Improved file upload configuration now offers additional customization options for handling file uploads, allowing users to fine-tune upload behavior.

… options

- Add support for passing custom Uppy and XHRUpload configuration options
- Update `IUploadConfig` interface to include `uppyConfig` and `xhrConfig`
- Spread additional configuration options in `createUploader`
@cycleccc cycleccc linked an issue Mar 2, 2025 that may be closed by this pull request
Copy link
Contributor

coderabbitai bot commented Mar 2, 2025

Walkthrough

This update enhances the file upload configuration in the editor and core packages by introducing additional configurable options for Uppy and XHRUpload. The modifications include adding spread operator lines in the uploader creation function and extending the upload configuration interface with new optional properties.

Changes

File(s) Change Summary
.changeset/twelve-seahorses-cross.md Added documentation summarizing the feature enhancement to support additional Uppy and XHRUpload configuration options in the uploader.
packages/core/src/upload/createUploader.ts, packages/core/src/upload/interface.ts Enhanced uploader configuration by adding spread operator lines (...config.uppyConfig and ...config.xhrConfig) in the uploader creation function, and by introducing optional uppyConfig and xhrConfig properties in the upload interface.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Uploader
    participant Uppy
    participant XHRUpload

    Client->>Uploader: Initialize upload with config (including uppyConfig, xhrConfig)
    Uploader->>Uppy: Create instance with base config + ...uppyConfig
    Uploader->>XHRUpload: Create instance with base config + ...xhrConfig
    Uppy-->>Uploader: Return Uppy instance
    XHRUpload-->>Uploader: Return XHRUpload instance
    Uploader-->>Client: Return configured uploader
Loading

Poem

I'm a rabbit hopping through the code,
Spreading joy with each new mode.
Uppy and XHR now set the pace,
Extra config makes our race a grace.
In digital hops, the changes gleam,
A coder's dream, or so it seems!
Hoppy updates light our stream!

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, 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 generate docstrings to generate docstrings for this 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 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 for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/core/src/upload/interface.ts (1)

44-47: Consider adding type safety for advanced users

While Record<string, any> provides maximum flexibility, consider adding more specific type definitions or references to Uppy types for better developer experience and type safety. This could be done by importing and using Uppy's own type definitions if available.

// Example of how this could be implemented:
import { UppyOptions } from '@uppy/core';
import { XHRUploadOptions } from '@uppy/xhr-upload';

// Then in the interface:
uppyConfig?: Partial<UppyOptions>;
xhrConfig?: Partial<XHRUploadOptions>;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2e00706 and 794d5b2.

📒 Files selected for processing (3)
  • .changeset/twelve-seahorses-cross.md (1 hunks)
  • packages/core/src/upload/createUploader.ts (1 hunks)
  • packages/core/src/upload/interface.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: test-e2e
  • GitHub Check: test
🔇 Additional comments (6)
.changeset/twelve-seahorses-cross.md (1)

1-7: LGTM: Changeset correctly documents the change

The changeset properly documents the feature enhancement to both affected packages with appropriate version updates (patch) and clear description.

packages/core/src/upload/createUploader.ts (3)

59-59: Good enhancement for flexible configuration

The spread operator allows for passing additional Uppy configuration options, providing users with more flexibility without modifying the core implementation.


68-68: Good enhancement for XHRUpload configuration

Adding the spread operator for XHRUpload options allows users to configure advanced XHRUpload settings without changing the core implementation.


61-63:

❓ Verification inconclusive

Verify potential override concerns

The position of the spread operator after core configuration values is correct, ensuring that user-provided configs can override default values if needed. However, be aware that this could potentially allow users to override critical configurations like endpoint and headers which might lead to unexpected behavior.


🏁 Script executed:

#!/bin/bash
# Check if there are any usage examples or documentation that mention uppyConfig or xhrConfig
rg -A 5 -B 5 "uppyConfig|xhrConfig" --type md

Length of output: 47


🏁 Script executed:

#!/bin/bash
# Check how the spread operator is applied in createUploader.ts to merge user configs
rg "\.\.\." packages/core/src/upload/createUploader.ts

Length of output: 150


Configuration Merge Override Check

The implementation in packages/core/src/upload/createUploader.ts correctly positions the spread operators after setting the core configuration values:

    endpoint: url,
    headers,
    formData: true,

This ensures that any values provided via config.uppyConfig and config.xhrConfig (as seen in the spread for merging additional options) will override the defaults. Please verify that allowing user-provided overrides for critical configurations like endpoint and headers is intentional and won’t lead to unexpected behavior.

packages/core/src/upload/interface.ts (2)

44-45: LGTM: Well-documented interface addition

The addition of uppyConfig with appropriate documentation comment is clear and follows the existing style of the interface. Using Record<string, any> is appropriate for this case as Uppy accepts various configuration options.


46-47: LGTM: Well-documented interface addition

The addition of xhrConfig with appropriate documentation comment is clear and follows the existing style of the interface. Using Record<string, any> is appropriate for this case as XHRUpload accepts various configuration options.

@cycleccc cycleccc merged commit 71397d4 into master Mar 3, 2025
3 checks passed
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.

Bug:同名图片上传遇到问题,需处理 Uppy 参数
1 participant