fix(image): 处理绝对路径和相对路径的文件路径转换

This commit is contained in:
SXP-Simon
2026-02-22 15:33:01 +08:00
parent ba30818212
commit e4819c866d
2 changed files with 10 additions and 2 deletions
+4 -1
View File
@@ -328,7 +328,10 @@ class GroupDailyAnalysis(Star):
parts = image_url.split(",", 1)
data = base64.b64decode(parts[1]) if len(parts) == 2 else None
elif os.path.isfile(image_url):
image_file = os.path.abspath(image_url)
if os.path.isabs(image_url):
image_file = image_url
else:
image_file = os.path.abspath(image_url)
data = None
else:
return
@@ -474,7 +474,12 @@ class OneBotAdapter(PlatformAdapter):
# 1) 优先尝试物理路径;2) 路径失败则回退 Base64
file_str = image_path
if not image_path.startswith(("http://", "https://", "base64://")):
file_str = f"file:///{os.path.abspath(image_path)}"
if os.path.isabs(image_path):
# 如果是绝对路径,保持原样(兼容 Docker 中的 /AstrBot/ 路径)
file_str = f"file:///{image_path}"
else:
# 如果是相对路径,转为绝对路径
file_str = f"file:///{os.path.abspath(image_path)}"
try:
message = list(base_message)