Skip to content

fix: 优化文件下载器方法 #6617

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lghuahua
Copy link
Contributor

@lghuahua lghuahua commented Aug 8, 2025

支持除GET以外的其他方法,由用户自己决定

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability of file downloads by ensuring the correct HTTP method is used.

Copy link

changeset-bot bot commented Aug 8, 2025

⚠️ No Changeset found

Latest commit: df65501

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Copy link
Contributor

coderabbitai bot commented Aug 8, 2025

Walkthrough

The download method in the FileDownloader class was updated to explicitly specify the HTTP method as 'GET' and to use the client's generic request method instead of the specialized get method. No changes were made to public APIs or exported entity signatures.

Changes

Cohort / File(s) Change Summary
Downloader Method Update
packages/effects/request/src/request-client/modules/downloader.ts
Modified the download method to set HTTP method to 'GET' and use the generic request method with configuration.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Suggested reviewers

  • mynetfan
  • anncwb
  • jinmao88

Poem

A bunny hopped by with a code to inspect,
Changed a download method, as you'd expect.
Now GET is explicit, requests are precise,
The client’s more general—oh, isn’t that nice?
With carrots in paw, I say with delight:
Review this small patch, then hop off tonight! 🥕

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
  • 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 explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests 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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9fc5944 and df65501.

📒 Files selected for processing (1)
  • packages/effects/request/src/request-client/modules/downloader.ts (1 hunks)
🧰 Additional context used
🪛 GitHub Check: Test (ubuntu-latest)
packages/effects/request/src/request-client/modules/downloader.ts

[failure] 36-36: packages/effects/request/src/request-client/modules/downloader.test.ts > fileDownloader > should merge provided config with default config
TypeError: this.client.request is not a function
❯ FileDownloader.download packages/effects/request/src/request-client/modules/downloader.ts:36:40
❯ packages/effects/request/src/request-client/modules/downloader.test.ts:49:41


[failure] 36-36: packages/effects/request/src/request-client/modules/downloader.test.ts > fileDownloader > should download a file and return a Blob
TypeError: this.client.request is not a function
❯ FileDownloader.download packages/effects/request/src/request-client/modules/downloader.ts:36:40
❯ packages/effects/request/src/request-client/modules/downloader.test.ts:28:41

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Check (ubuntu-latest)
  • GitHub Check: Check (windows-latest)
  • GitHub Check: Lint (windows-latest)
  • GitHub Check: Lint (ubuntu-latest)
  • GitHub Check: post-update (windows-latest)
  • GitHub Check: post-update (ubuntu-latest)
🔇 Additional comments (1)
packages/effects/request/src/request-client/modules/downloader.ts (1)

29-34: Default method placement and binary response config validated

  • method: 'GET' is set before ...config, allowing callers to override the HTTP method
  • responseType: 'blob' is after ...config, enforcing binary download responses
  • Verified that RequestClient exposes get, post, put, delete, and a generic request method that forwards the method field to Axios

...config,
responseType: 'blob',
};

const response = await this.client.get<T>(url, finalConfig);
const response = await this.client.request<T>(url, finalConfig);
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Regression: switching to this.client.request breaks existing clients/mocks (tests failing).

Static analysis shows TypeError: this.client.request is not a function. The RequestClient in this codebase (and its tests) likely doesn’t expose request(url, config). This change breaks backward compatibility.

Proposed fix: add a safe dispatch that prefers request when available, otherwise falls back to get for GET and to method-specific calls for others.

Apply this diff to lines around the request invocation:

-    const response = await this.client.request<T>(url, finalConfig);
-
-    return response;
+    // Prefer a generic request if available; otherwise, dispatch to method-specific calls.
+    const method = (finalConfig.method || 'GET').toUpperCase();
+    const clientAny = this.client as any;
+    const lower = method.toLowerCase();
+
+    if (typeof clientAny.request === 'function') {
+      return await clientAny.request<T>(url, finalConfig);
+    }
+
+    // Fallbacks for common method signatures
+    if (method === 'GET' && typeof clientAny.get === 'function') {
+      return await clientAny.get<T>(url, finalConfig);
+    }
+
+    if (['POST', 'PUT', 'PATCH'].includes(method) && typeof clientAny[lower] === 'function') {
+      const { data, ...rest } = finalConfig as Record<string, any>;
+      return await clientAny[lower]<T>(url, data, rest);
+    }
+
+    if (['DELETE', 'HEAD', 'OPTIONS'].includes(method) && typeof clientAny[lower] === 'function') {
+      return await clientAny[lower]<T>(url, finalConfig);
+    }
+
+    throw new Error(`RequestClient does not support method "${method}"`);

Alternatively (bigger change): add request(url, config) to RequestClient, update its implementations and tests to stub request.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const response = await this.client.request<T>(url, finalConfig);
// Prefer a generic request if available; otherwise, dispatch to method-specific calls.
const method = (finalConfig.method || 'GET').toUpperCase();
const clientAny = this.client as any;
const lower = method.toLowerCase();
if (typeof clientAny.request === 'function') {
return await clientAny.request<T>(url, finalConfig);
}
// Fallbacks for common method signatures
if (method === 'GET' && typeof clientAny.get === 'function') {
return await clientAny.get<T>(url, finalConfig);
}
if (['POST', 'PUT', 'PATCH'].includes(method) && typeof clientAny[lower] === 'function') {
const { data, ...rest } = finalConfig as Record<string, any>;
return await clientAny[lower]<T>(url, data, rest);
}
if (['DELETE', 'HEAD', 'OPTIONS'].includes(method) && typeof clientAny[lower] === 'function') {
return await clientAny[lower]<T>(url, finalConfig);
}
throw new Error(`RequestClient does not support method "${method}"`);
🧰 Tools
🪛 GitHub Check: Test (ubuntu-latest)

[failure] 36-36: packages/effects/request/src/request-client/modules/downloader.test.ts > fileDownloader > should merge provided config with default config
TypeError: this.client.request is not a function
❯ FileDownloader.download packages/effects/request/src/request-client/modules/downloader.ts:36:40
❯ packages/effects/request/src/request-client/modules/downloader.test.ts:49:41


[failure] 36-36: packages/effects/request/src/request-client/modules/downloader.test.ts > fileDownloader > should download a file and return a Blob
TypeError: this.client.request is not a function
❯ FileDownloader.download packages/effects/request/src/request-client/modules/downloader.ts:36:40
❯ packages/effects/request/src/request-client/modules/downloader.test.ts:28:41

🤖 Prompt for AI Agents
In packages/effects/request/src/request-client/modules/downloader.ts at line 36,
the direct call to this.client.request(url, finalConfig) causes a TypeError
because RequestClient may not implement a request method, breaking existing
clients and mocks. To fix this, implement a safe dispatch that first checks if
this.client.request exists and calls it if so; otherwise, for GET requests call
this.client.get(url, config), and for other HTTP methods call the corresponding
method-specific function on this.client. This preserves backward compatibility
without requiring immediate changes to RequestClient interface or its tests.

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.

1 participant