mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
✨ 优化文件内容获取逻辑,新增对非二进制文件的UTF-8解码处理,提升文件读取的稳定性和准确性。
This commit is contained in:
parent
a6031ee091
commit
3d90734534
@ -82,18 +82,20 @@ class RepoFileManager:
|
|||||||
)
|
)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
logger.info(f"获取github文件内容成功: {f}", LOG_COMMAND)
|
logger.info(f"获取github文件内容成功: {f}", LOG_COMMAND)
|
||||||
|
text_content = response.content
|
||||||
# 确保使用UTF-8编码解析响应内容
|
# 确保使用UTF-8编码解析响应内容
|
||||||
try:
|
if not is_binary_file(f):
|
||||||
text_content = response.content.decode("utf-8")
|
try:
|
||||||
except UnicodeDecodeError:
|
text_content = response.content.decode("utf-8")
|
||||||
# 如果UTF-8解码失败,尝试其他编码
|
except UnicodeDecodeError:
|
||||||
text_content = response.content.decode(
|
# 如果UTF-8解码失败,尝试其他编码
|
||||||
"utf-8", errors="ignore"
|
text_content = response.content.decode(
|
||||||
)
|
"utf-8", errors="ignore"
|
||||||
logger.warning(
|
)
|
||||||
f"解码文件内容时出现错误,使用忽略错误模式: {f}",
|
logger.warning(
|
||||||
LOG_COMMAND,
|
f"解码文件内容时出现错误,使用忽略错误模式:{f}",
|
||||||
)
|
LOG_COMMAND,
|
||||||
|
)
|
||||||
results.append((f, text_content))
|
results.append((f, text_content))
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user