update:获取差异化配置时,不输出敏感信息

This commit is contained in:
hrz
2025-04-28 16:30:31 +08:00
parent 90a31debd1
commit 1f5a78f458
2 changed files with 72 additions and 38 deletions
+36 -3
View File
@@ -241,7 +241,7 @@ class ConnectionHandler:
) )
private_config["delete_audio"] = bool(self.config.get("delete_audio", True)) private_config["delete_audio"] = bool(self.config.get("delete_audio", True))
self.logger.bind(tag=TAG).info( self.logger.bind(tag=TAG).info(
f"{time.time() - begin_time} 秒,获取差异化配置成功: {private_config}" f"{time.time() - begin_time} 秒,获取差异化配置成功: {json.dumps(filter_sensitive_info(private_config), ensure_ascii=False)}"
) )
except DeviceNotFoundException as e: except DeviceNotFoundException as e:
self.need_bind = True self.need_bind = True
@@ -448,7 +448,7 @@ class ConnectionHandler:
pos = current_text.rfind(punct) pos = current_text.rfind(punct)
prev_char = current_text[pos - 1] if pos - 1 >= 0 else "" prev_char = current_text[pos - 1] if pos - 1 >= 0 else ""
# 如果.前面是数字统一判断为小数 # 如果.前面是数字统一判断为小数
if prev_char.isdigit() and punct == '.': if prev_char.isdigit() and punct == ".":
number_flag = False number_flag = False
if pos > last_punct_pos and number_flag: if pos > last_punct_pos and number_flag:
last_punct_pos = pos last_punct_pos = pos
@@ -579,7 +579,7 @@ class ConnectionHandler:
pos = current_text.rfind(punct) pos = current_text.rfind(punct)
prev_char = current_text[pos - 1] if pos - 1 >= 0 else "" prev_char = current_text[pos - 1] if pos - 1 >= 0 else ""
# 如果.前面是数字统一判断为小数 # 如果.前面是数字统一判断为小数
if prev_char.isdigit() and punct == '.': if prev_char.isdigit() and punct == ".":
number_flag = False number_flag = False
if pos > last_punct_pos and number_flag: if pos > last_punct_pos and number_flag:
last_punct_pos = pos last_punct_pos = pos
@@ -945,3 +945,36 @@ class ConnectionHandler:
break break
except Exception as e: except Exception as e:
self.logger.bind(tag=TAG).error(f"超时检查任务出错: {e}") self.logger.bind(tag=TAG).error(f"超时检查任务出错: {e}")
def filter_sensitive_info(config: dict) -> dict:
"""
过滤配置中的敏感信息
Args:
config: 原始配置字典
Returns:
过滤后的配置字典
"""
sensitive_keys = [
"api_key",
"personal_access_token",
"access_token",
"token",
"access_key_secret",
"secret_key",
]
def _filter_dict(d: dict) -> dict:
filtered = {}
for k, v in d.items():
if any(sensitive in k.lower() for sensitive in sensitive_keys):
filtered[k] = "***"
elif isinstance(v, dict):
filtered[k] = _filter_dict(v)
elif isinstance(v, list):
filtered[k] = [_filter_dict(i) if isinstance(i, dict) else i for i in v]
else:
filtered[k] = v
return filtered
return _filter_dict(copy.deepcopy(config))
@@ -2,51 +2,52 @@ from config.logger import setup_logging
import json import json
import asyncio import asyncio
import time import time
from core.utils.util import ( from core.utils.util import get_string_no_punctuation_or_emoji, analyze_emotion
get_string_no_punctuation_or_emoji,
analyze_emotion
)
TAG = __name__ TAG = __name__
logger = setup_logging() logger = setup_logging()
emoji_map = { emoji_map = {
'neutral': '😶', "neutral": "😶",
'happy': '🙂', "happy": "🙂",
'laughing': '😆', "laughing": "😆",
'funny': '😂', "funny": "😂",
'sad': '😔', "sad": "😔",
'angry': '😠', "angry": "😠",
'crying': '😭', "crying": "😭",
'loving': '😍', "loving": "😍",
'embarrassed': '😳', "embarrassed": "😳",
'surprised': '😲', "surprised": "😲",
'shocked': '😱', "shocked": "😱",
'thinking': '🤔', "thinking": "🤔",
'winking': '😉', "winking": "😉",
'cool': '😎', "cool": "😎",
'relaxed': '😌', "relaxed": "😌",
'delicious': '🤤', "delicious": "🤤",
'kissy': '😘', "kissy": "😘",
'confident': '😏', "confident": "😏",
'sleepy': '😴', "sleepy": "😴",
'silly': '😜', "silly": "😜",
'confused': '🙄' "confused": "🙄",
} }
async def sendAudioMessage(conn, audios, text, text_index=0): async def sendAudioMessage(conn, audios, text, text_index=0):
# 发送句子开始消息 # 发送句子开始消息
emotion = analyze_emotion(text) if text is not None:
emoji = emoji_map.get(emotion, '🙂') # 默认使用笑脸 emotion = analyze_emotion(text)
await conn.websocket.send(json.dumps( emoji = emoji_map.get(emotion, "🙂") # 默认使用笑脸
{ await conn.websocket.send(
"type": "llm", json.dumps(
"text": emoji, {
"emotion": emotion, "type": "llm",
"session_id": conn.session_id, "text": emoji,
} "emotion": emotion,
"session_id": conn.session_id,
}
)
) )
)
if text_index == conn.tts_first_text_index: if text_index == conn.tts_first_text_index:
logger.bind(tag=TAG).info(f"发送第一段语音: {text}") logger.bind(tag=TAG).info(f"发送第一段语音: {text}")
await send_tts_message(conn, "sentence_start", text) await send_tts_message(conn, "sentence_start", text)