perf: 优化图片渲染

This commit is contained in:
Rock Chin
2023-03-04 23:53:22 +08:00
parent 7440e9e5d2
commit a457d13d2c
2 changed files with 14 additions and 8 deletions
+7 -2
View File
@@ -1,4 +1,5 @@
# 长消息处理相关
import logging
import os
import time
import base64
@@ -54,7 +55,10 @@ def text_to_image(text: str) -> MessageComponent:
# 删除图片
os.remove(img_path)
os.remove(compressed_path)
# 判断compressed_path是否存在
if os.path.exists(compressed_path):
os.remove(compressed_path)
# 返回图片
return Image(base64=b64.decode('utf-8'))
@@ -67,7 +71,8 @@ def check_text(text: str) -> list:
if len(text) > config.blob_message_threshold:
if not hasattr(config, 'blob_message_strategy'):
raise AttributeError('未定义长消息处理策略')
# logging.info("长消息: {}".format(text))
if config.blob_message_strategy == 'image':
# 转换成图片
return [text_to_image(text)]