fix(weixin_oc): allow CDN uploads to use upload_full_url when provided #7066
fix(weixin_oc): allow CDN uploads to use upload_full_url when provided #7066Soulter merged 3 commits intoAstrBotDevs:masterfrom
upload_full_url when provided #7066Conversation
适配微信开放平台`getuploadurl`接口返回的新格式,该接口现在可能返回`upload_full_url`字段。 优先使用`upload_full_url`作为上传地址,以保持上传功能正常。
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
upload_to_cdn, the parameter order (upload_parambeforeupload_full_url) is opposite to the new priority logic; consider reordering the arguments or using keyword-only parameters at the call site to make it harder to accidentally swap them in future changes. - You currently normalize and trim
upload_param/upload_full_urlboth in the adapter and again in the client; consider consolidating this normalization in one place (adapter or client) to avoid duplicated logic and potential divergence later.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `upload_to_cdn`, the parameter order (`upload_param` before `upload_full_url`) is opposite to the new priority logic; consider reordering the arguments or using keyword-only parameters at the call site to make it harder to accidentally swap them in future changes.
- You currently normalize and trim `upload_param`/`upload_full_url` both in the adapter and again in the client; consider consolidating this normalization in one place (adapter or client) to avoid duplicated logic and potential divergence later.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
This pull request adds support for upload_full_url in the WeChat OC adapter and client, enabling direct CDN uploads. The upload_to_cdn method now handles both full URLs and parameter-based URL construction. A suggestion was made to use the walrus operator to simplify the URL cleaning and validation logic in the client.
- 在适配器中,将通用错误信息具体化为“CDN上传URL缺失” - 在客户端中,移除冗余的参数处理逻辑,使参数验证更清晰
|
@gemini-code-assist review |
There was a problem hiding this comment.
Code Review
This pull request introduces support for using a full upload URL in the WeChat OC CDN upload process, allowing the system to bypass manual URL construction when upload_full_url is provided. The review identified a critical bug where the parameter order in the upload_to_cdn call in the adapter does not match the updated function signature in the client, which would cause logic errors. Additionally, there is redundant validation logic and inconsistent exception handling between the adapter and the client that should be consolidated to improve code maintainability.
| upload_param, | ||
| upload_full_url, |
|
@sourcery-ai review |
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The
upload_to_cdnparameter order is inconsistent betweenweixin_oc_client.pyandweixin_oc_adapter.py: the method now expects(upload_full_url, upload_param, ...)but the adapter is calling it as(upload_param, upload_full_url, ...), which will swap the values at runtime and should be corrected. - Since
upload_full_urlandupload_paramare mutually alternative inputs, consider making both keyword-only or giving them explicit names at call sites to avoid similar ordering issues in future refactors.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `upload_to_cdn` parameter order is inconsistent between `weixin_oc_client.py` and `weixin_oc_adapter.py`: the method now expects `(upload_full_url, upload_param, ...)` but the adapter is calling it as `(upload_param, upload_full_url, ...)`, which will swap the values at runtime and should be corrected.
- Since `upload_full_url` and `upload_param` are mutually alternative inputs, consider making both keyword-only or giving them explicit names at call sites to avoid similar ordering issues in future refactors.
## Individual Comments
### Comment 1
<location path="astrbot/core/platform/sources/weixin_oc/weixin_oc_adapter.py" line_range="602-607" />
<code_context>
+ "CDN upload URL missing (need upload_full_url or upload_param)"
+ )
encrypted_query_param = await self.client.upload_to_cdn(
upload_param,
+ upload_full_url,
file_key,
aes_key_hex,
media_path,
</code_context>
<issue_to_address>
**issue (bug_risk):** Arguments to `upload_to_cdn` appear swapped relative to the updated function signature.
The updated signature is `(self, upload_full_url, upload_param, file_key, aes_key_hex, media_path)`, but this call passes `(upload_param, upload_full_url, ...)`, so the URL and param are reversed. This will select the wrong URL and can raise a `ValueError` even for valid URLs. Please swap the first two arguments to match the new signature.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
移除对weixin_oc_adapter中upload_param和upload_full_url同时为空的检查,因为逻辑上已由底层方法保证。 调整upload_to_cdn方法的参数顺序以匹配其内部实现,确保正确传递。
|
@gemini-code-assist review |
There was a problem hiding this comment.
Code Review
This pull request updates the WeChat Official Account (weixin_oc) platform source to support a full upload URL (upload_full_url) in addition to the existing parameter-based URL construction. Changes include extracting the full URL in the adapter and updating the CDN upload client to prioritize the full URL if available. A review comment suggests adding a validation check in the adapter to ensure at least one upload method is provided, which would improve error reporting by catching missing parameters earlier in the process.
|
@sourcery-ai review |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Changing
upload_to_cdnto take a new leading positional argument (upload_full_url) risks subtle breakage for any existing callers; consider making it a keyword-only or optional argument with a default to preserve the previous call signature. - Since
upload_full_urlis now preferred overupload_param, it may be helpful to include the chosen URL (or at least which path was taken) in the debug log to aid in diagnosing CDN upload issues with mixed response formats.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Changing `upload_to_cdn` to take a new leading positional argument (`upload_full_url`) risks subtle breakage for any existing callers; consider making it a keyword-only or optional argument with a default to preserve the previous call signature.
- Since `upload_full_url` is now preferred over `upload_param`, it may be helpful to include the chosen URL (or at least which path was taken) in the debug log to aid in diagnosing CDN upload issues with mixed response formats.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
upload_full_url when provided
适配微信开放平台
getuploadurl接口返回的新格式,该接口现在可能返回upload_full_url字段。 优先使用upload_full_url作为上传地址,以保持上传功能正常。当前会出现返回upload_param为空的问题导致发送失败
Modifications / 改动点
weixin_oc_adapter.py 增加upload_full_url参数校验
weixin_oc_client.py 增加upload_full_url参数赋值给cdn_url
This is NOT a breaking change. / 这不是一个破坏性变更。
Screenshots or Test Results / 运行截图或测试结果
Checklist / 检查清单
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。
Summary by Sourcery
Bug Fixes: