Skip to content

Commit fcfd6a9

Browse files
authored
fix(weixin_oc): allow CDN uploads to use upload_full_url when provided (#7066)
* fix(weixin_oc): 处理微信开放平台CDN上传URL的新格式 适配微信开放平台`getuploadurl`接口返回的新格式,该接口现在可能返回`upload_full_url`字段。 优先使用`upload_full_url`作为上传地址,以保持上传功能正常。 * fix(weixin_oc): 改进CDN上传URL缺失时的错误信息 - 在适配器中,将通用错误信息具体化为“CDN上传URL缺失” - 在客户端中,移除冗余的参数处理逻辑,使参数验证更清晰 * fix(weixin_oc): 调整CDN上传参数顺序并移除冗余检查 移除对weixin_oc_adapter中upload_param和upload_full_url同时为空的检查,因为逻辑上已由底层方法保证。 调整upload_to_cdn方法的参数顺序以匹配其内部实现,确保正确传递。
1 parent 9238ad5 commit fcfd6a9

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

astrbot/core/platform/sources/weixin_oc/weixin_oc_adapter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,10 +593,10 @@ async def _prepare_media_item(
593593
len(str(payload.get("upload_param", ""))),
594594
)
595595
upload_param = str(payload.get("upload_param", "")).strip()
596-
if not upload_param:
597-
raise RuntimeError("getuploadurl returned empty upload_param")
596+
upload_full_url = str(payload.get("upload_full_url", "")).strip()
598597

599598
encrypted_query_param = await self.client.upload_to_cdn(
599+
upload_full_url,
600600
upload_param,
601601
file_key,
602602
aes_key_hex,

astrbot/core/platform/sources/weixin_oc/weixin_oc_client.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,21 @@ def parse_media_aes_key(aes_key_value: str) -> bytes:
108108

109109
async def upload_to_cdn(
110110
self,
111+
upload_full_url: str,
111112
upload_param: str,
112113
file_key: str,
113114
aes_key_hex: str,
114115
media_path: Path,
115116
) -> str:
117+
if upload_full_url:
118+
cdn_url = upload_full_url
119+
elif upload_param:
120+
cdn_url = self._build_cdn_upload_url(upload_param, file_key)
121+
else:
122+
raise ValueError(
123+
"CDN upload URL missing (need upload_full_url or upload_param)"
124+
)
125+
116126
raw_data = media_path.read_bytes()
117127
logger.debug(
118128
"weixin_oc(%s): prepare CDN upload file=%s size=%s md5=%s filekey=%s",
@@ -135,7 +145,6 @@ async def upload_to_cdn(
135145
await self.ensure_http_session()
136146
assert self._http_session is not None
137147
timeout = aiohttp.ClientTimeout(total=self.api_timeout_ms / 1000)
138-
cdn_url = self._build_cdn_upload_url(upload_param, file_key)
139148

140149
async with self._http_session.post(
141150
cdn_url,

0 commit comments

Comments
 (0)