fix:自动清理缓存图片

This commit is contained in:
SengokuCola
2025-04-04 00:55:25 +08:00
parent 6bbd94373a
commit cd50a15181
2 changed files with 31 additions and 2 deletions

View File

@@ -2,8 +2,10 @@
## [test-0.6.0-snapshot-8] - 2025-4-3 ## [test-0.6.0-snapshot-8] - 2025-4-3
- 修复了表情包的注册,获取和发送逻辑 - 修复了表情包的注册,获取和发送逻辑
- 表情包增加存储上限
- 更改了回复引用的逻辑,从基于时间改为基于新消息 - 更改了回复引用的逻辑,从基于时间改为基于新消息
- 增加了调试信息 - 增加了调试信息
- 自动清理缓存图片
## [test-0.6.0-snapshot-7] - 2025-4-2 ## [test-0.6.0-snapshot-7] - 2025-4-2
- 修改版本号命名test-前缀为测试版,无前缀为正式版 - 修改版本号命名test-前缀为测试版,无前缀为正式版

View File

@@ -535,9 +535,36 @@ class EmojiManager:
while True: while True:
self.check_emoji_file_full() self.check_emoji_file_full()
self.check_emoji_file_integrity() self.check_emoji_file_integrity()
await self.delete_all_images()
await asyncio.sleep(global_config.EMOJI_CHECK_INTERVAL * 60) await asyncio.sleep(global_config.EMOJI_CHECK_INTERVAL * 60)
async def delete_all_images(self):
"""删除 data/image 目录下的所有文件"""
try:
image_dir = os.path.join("data", "image")
if not os.path.exists(image_dir):
logger.warning(f"[警告] 目录不存在: {image_dir}")
return
deleted_count = 0
failed_count = 0
# 遍历目录下的所有文件
for filename in os.listdir(image_dir):
file_path = os.path.join(image_dir, filename)
try:
if os.path.isfile(file_path):
os.remove(file_path)
deleted_count += 1
logger.debug(f"[删除] 文件: {file_path}")
except Exception as e:
failed_count += 1
logger.error(f"[错误] 删除文件失败 {file_path}: {str(e)}")
logger.success(f"[清理] 已删除 {deleted_count} 个文件,失败 {failed_count}")
except Exception as e:
logger.error(f"[错误] 删除图片目录失败: {str(e)}")
# 创建全局单例 # 创建全局单例
emoji_manager = EmojiManager() emoji_manager = EmojiManager()