-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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
base: main
Are you sure you want to change the base?
fix: 优化文件下载器方法 #6617
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -28,13 +28,32 @@ class FileDownloader { | |||||||||||||||||||||||||||||||||||||||||
): Promise<T> { | ||||||||||||||||||||||||||||||||||||||||||
const finalConfig: DownloadRequestConfig = { | ||||||||||||||||||||||||||||||||||||||||||
responseReturn: 'body', | ||||||||||||||||||||||||||||||||||||||||||
method: 'GET', | ||||||||||||||||||||||||||||||||||||||||||
...config, | ||||||||||||||||||||||||||||||||||||||||||
responseType: 'blob', | ||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
const response = await this.client.get<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; | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
return response; | ||||||||||||||||||||||||||||||||||||||||||
if (typeof clientAny.request === 'function') { | ||||||||||||||||||||||||||||||||||||||||||
return await clientAny.request(url, finalConfig); | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
const lower = method.toLowerCase(); | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
if (typeof clientAny[lower] === 'function') { | ||||||||||||||||||||||||||||||||||||||||||
if (['POST', 'PUT'].includes(method)) { | ||||||||||||||||||||||||||||||||||||||||||
const { data, ...rest } = finalConfig as Record<string, any>; | ||||||||||||||||||||||||||||||||||||||||||
return await clientAny[lower](url, data, rest); | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
return await clientAny[lower](url, finalConfig); | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+45
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion PATCH is treated like GET here — body is dropped. Axios-style Apply this diff to include - if (typeof clientAny[lower] === 'function') {
- if (['POST', 'PUT'].includes(method)) {
- const { data, ...rest } = finalConfig as Record<string, any>;
- return await clientAny[lower](url, data, rest);
- }
-
- return await clientAny[lower](url, finalConfig);
- }
+ if (typeof clientAny[lower] === 'function') {
+ if (['POST', 'PUT', 'PATCH'].includes(method)) {
+ const { data, ...rest } = finalConfig as Record<string, any>;
+ return await clientAny[lower](url, data, rest);
+ }
+ if (method === 'GET') {
+ // Avoid accidental bodies on GET
+ const { data: _ignored, ...rest } = finalConfig as Record<string, any>;
+ return await clientAny[lower](url, rest);
+ }
+ return await clientAny[lower](url, finalConfig);
+ } 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
throw new Error( | ||||||||||||||||||||||||||||||||||||||||||
`RequestClient does not support method "${method}". Please ensure the method is properly implemented in your RequestClient instance.`, | ||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix async rejection assertion (use a Promise, not a function).
rejects
matcher expects a Promise: wrap the awaited call directly. Current form may not fail as intended.Apply this diff:
📝 Committable suggestion
🤖 Prompt for AI Agents