mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-08-10 21:10:59 +00:00
feat: update file download url
This commit is contained in:
@@ -23,7 +23,7 @@ class GewechatConfigMigration(migration.Migration):
|
|||||||
"adapter": "gewechat",
|
"adapter": "gewechat",
|
||||||
"enable": False,
|
"enable": False,
|
||||||
"gewechat_url": "http://your-gewechat-server:2531",
|
"gewechat_url": "http://your-gewechat-server:2531",
|
||||||
"gewechat_downloadImage_port": 2532,
|
"gewechat_file_url": "http://your-gewechat-server:2532",
|
||||||
"port": 2286,
|
"port": 2286,
|
||||||
"callback_url": "http://your-callback-url:2286/gewechat/callback",
|
"callback_url": "http://your-callback-url:2286/gewechat/callback",
|
||||||
"app_id": "",
|
"app_id": "",
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
from .. import migration
|
||||||
|
|
||||||
|
|
||||||
|
@migration.migration_class("gewechat-file-url-config", 34)
|
||||||
|
class GewechatFileUrlConfigMigration(migration.Migration):
|
||||||
|
"""迁移"""
|
||||||
|
|
||||||
|
async def need_migrate(self) -> bool:
|
||||||
|
"""判断当前环境是否需要运行此迁移"""
|
||||||
|
|
||||||
|
for adapter in self.ap.platform_cfg.data['platform-adapters']:
|
||||||
|
if adapter['adapter'] == 'gewechat':
|
||||||
|
if 'gewechat_file_url' not in adapter:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
async def run(self):
|
||||||
|
"""执行迁移"""
|
||||||
|
for adapter in self.ap.platform_cfg.data['platform-adapters']:
|
||||||
|
if adapter['adapter'] == 'gewechat':
|
||||||
|
if 'gewechat_file_url' not in adapter:
|
||||||
|
parsed_url = urlparse(adapter['gewechat_url'])
|
||||||
|
adapter['gewechat_file_url'] = f"{parsed_url.scheme}://{parsed_url.hostname}:2532"
|
||||||
|
|
||||||
|
await self.ap.platform_cfg.dump_config()
|
||||||
@@ -11,7 +11,7 @@ from ..migrations import m015_gitee_ai_config, m016_dify_service_api, m017_dify_
|
|||||||
from ..migrations import m020_wecom_config, m021_lark_config, m022_lmstudio_config, m023_siliconflow_config, m024_discord_config, m025_gewechat_config
|
from ..migrations import m020_wecom_config, m021_lark_config, m022_lmstudio_config, m023_siliconflow_config, m024_discord_config, m025_gewechat_config
|
||||||
from ..migrations import m026_qqofficial_config, m027_wx_official_account_config, m028_aliyun_requester_config
|
from ..migrations import m026_qqofficial_config, m027_wx_official_account_config, m028_aliyun_requester_config
|
||||||
from ..migrations import m029_dashscope_app_api_config, m030_lark_config_cmpl, m031_dingtalk_config, m032_volcark_config
|
from ..migrations import m029_dashscope_app_api_config, m030_lark_config_cmpl, m031_dingtalk_config, m032_volcark_config
|
||||||
from ..migrations import m033_dify_thinking_config
|
from ..migrations import m033_dify_thinking_config, m034_gewechat_file_url_config
|
||||||
|
|
||||||
@stage.stage_class("MigrationStage")
|
@stage.stage_class("MigrationStage")
|
||||||
class MigrationStage(stage.BootingStage):
|
class MigrationStage(stage.BootingStage):
|
||||||
|
|||||||
@@ -86,11 +86,11 @@ class GewechatMessageConverter(adapter.MessageConverter):
|
|||||||
try:
|
try:
|
||||||
base64_str, image_format = await image.get_gewechat_image_base64(
|
base64_str, image_format = await image.get_gewechat_image_base64(
|
||||||
gewechat_url=self.config["gewechat_url"],
|
gewechat_url=self.config["gewechat_url"],
|
||||||
|
gewechat_file_url=self.config["gewechat_file_url"]
|
||||||
app_id=self.config["app_id"],
|
app_id=self.config["app_id"],
|
||||||
xml_content=image_xml,
|
xml_content=image_xml,
|
||||||
token=self.config["token"],
|
token=self.config["token"],
|
||||||
image_type=2,
|
image_type=2,
|
||||||
download_image_port=self.config["gewechat_downloadImage_port"]
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return platform_message.MessageChain([
|
return platform_message.MessageChain([
|
||||||
|
|||||||
@@ -17,13 +17,13 @@ spec:
|
|||||||
type: string
|
type: string
|
||||||
required: true
|
required: true
|
||||||
default: ""
|
default: ""
|
||||||
- name: gewechat_downloadImage_port
|
- name: gewechat_file_url
|
||||||
label:
|
label:
|
||||||
en_US: GeWeChat download image port
|
en_US: GeWeChat file download URL
|
||||||
zh_CN: GeWeChat 下载图片的端口
|
zh_CN: GeWeChat 文件下载URL
|
||||||
type: int
|
type: string
|
||||||
required: true
|
required: true
|
||||||
default: 2532
|
default: ""
|
||||||
- name: port
|
- name: port
|
||||||
label:
|
label:
|
||||||
en_US: Port
|
en_US: Port
|
||||||
|
|||||||
+3
-4
@@ -17,21 +17,21 @@ from urllib.parse import urlparse
|
|||||||
|
|
||||||
async def get_gewechat_image_base64(
|
async def get_gewechat_image_base64(
|
||||||
gewechat_url: str,
|
gewechat_url: str,
|
||||||
|
gewechat_file_url: str,
|
||||||
app_id: str,
|
app_id: str,
|
||||||
xml_content: str,
|
xml_content: str,
|
||||||
token: str,
|
token: str,
|
||||||
image_type: int = 2,
|
image_type: int = 2,
|
||||||
download_image_port: int = 2532,
|
|
||||||
) -> typing.Tuple[str, str]:
|
) -> typing.Tuple[str, str]:
|
||||||
"""从gewechat服务器获取图片并转换为base64格式
|
"""从gewechat服务器获取图片并转换为base64格式
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
gewechat_url (str): gewechat服务器地址(用于获取图片URL)
|
gewechat_url (str): gewechat服务器地址(用于获取图片URL)
|
||||||
|
gewechat_file_url (str): gewechat文件下载服务地址
|
||||||
app_id (str): gewechat应用ID
|
app_id (str): gewechat应用ID
|
||||||
xml_content (str): 图片的XML内容
|
xml_content (str): 图片的XML内容
|
||||||
token (str): Gewechat API Token
|
token (str): Gewechat API Token
|
||||||
image_type (int, optional): 图片类型. Defaults to 2.
|
image_type (int, optional): 图片类型. Defaults to 2.
|
||||||
download_image_port (int, optional): 图片下载服务端口. Defaults to 2532.
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
typing.Tuple[str, str]: (base64编码, 图片格式)
|
typing.Tuple[str, str]: (base64编码, 图片格式)
|
||||||
@@ -80,8 +80,7 @@ async def get_gewechat_image_base64(
|
|||||||
raise Exception(f"获取图片下载链接网络错误: {str(e)}")
|
raise Exception(f"获取图片下载链接网络错误: {str(e)}")
|
||||||
|
|
||||||
# 解析原始URL并替换端口
|
# 解析原始URL并替换端口
|
||||||
parsed_url = urlparse(gewechat_url)
|
base_url = gewechat_file_url
|
||||||
base_url = f"http://{parsed_url.hostname}:{download_image_port}"
|
|
||||||
download_url = f"{base_url}/download/{file_url}"
|
download_url = f"{base_url}/download/{file_url}"
|
||||||
|
|
||||||
# 下载图片
|
# 下载图片
|
||||||
|
|||||||
@@ -64,7 +64,7 @@
|
|||||||
"adapter": "gewechat",
|
"adapter": "gewechat",
|
||||||
"enable": false,
|
"enable": false,
|
||||||
"gewechat_url": "http://your-gewechat-server:2531",
|
"gewechat_url": "http://your-gewechat-server:2531",
|
||||||
"gewechat_downloadImage_port": 2532,
|
"gewechat_file_url": "http://your-gewechat-server:2532",
|
||||||
"port": 2286,
|
"port": 2286,
|
||||||
"callback_url": "http://your-callback-url:2286/gewechat/callback",
|
"callback_url": "http://your-callback-url:2286/gewechat/callback",
|
||||||
"app_id": "",
|
"app_id": "",
|
||||||
|
|||||||
@@ -325,10 +325,10 @@
|
|||||||
"default": "",
|
"default": "",
|
||||||
"description": "gewechat 的 url"
|
"description": "gewechat 的 url"
|
||||||
},
|
},
|
||||||
"gewechat_downloadImage_port": {
|
"gewechat_file_url": {
|
||||||
"type": "integer",
|
"type": "string",
|
||||||
"default": 2532,
|
"default": "",
|
||||||
"description": "gewechat 下载图片的端口"
|
"description": "gewechat 文件下载URL"
|
||||||
},
|
},
|
||||||
"port": {
|
"port": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
|
|||||||
Reference in New Issue
Block a user