mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-09-01 23:27:14 +00:00
fix: dingtalk adapters couldn't handle images (#1500)
This commit is contained in:
@@ -80,17 +80,20 @@ class DingTalkClient:
|
|||||||
if download_url:
|
if download_url:
|
||||||
return await self.download_url_to_base64(download_url)
|
return await self.download_url_to_base64(download_url)
|
||||||
|
|
||||||
|
|
||||||
async def download_url_to_base64(self, download_url):
|
async def download_url_to_base64(self, download_url):
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
response = await client.get(download_url)
|
response = await client.get(download_url)
|
||||||
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
file_bytes = response.content
|
file_bytes = response.content
|
||||||
base64_str = base64.b64encode(file_bytes).decode('utf-8') # 返回字符串格式
|
mime_type = response.headers.get("Content-Type", "application/octet-stream")
|
||||||
return base64_str
|
base64_str = base64.b64encode(file_bytes).decode("utf-8")
|
||||||
|
return f"data:{mime_type};base64,{base64_str}"
|
||||||
else:
|
else:
|
||||||
await self.logger.error(f"failed to get files: {response.json()}")
|
await self.logger.error(f"failed to get files: {response.json()}")
|
||||||
|
|
||||||
|
|
||||||
async def get_audio_url(self, download_code: str):
|
async def get_audio_url(self, download_code: str):
|
||||||
if not await self.check_access_token():
|
if not await self.check_access_token():
|
||||||
await self.get_access_token()
|
await self.get_access_token()
|
||||||
|
|||||||
Reference in New Issue
Block a user