This commit is contained in:
jinql
2025-09-23 13:20:56 +08:00
parent 634cb504da
commit 7c44c6670a
3 changed files with 11 additions and 11 deletions

View File

@@ -184,9 +184,9 @@ def _is_default_icon_byte(file_content: bytes) -> bool:
return False
def _get_cache_file(domain: str, refresh: bool = False) -> Tuple[Optional[bytes], Optional[bytes]]:
def _get_cache_file(domain_md5: str, refresh: bool = False) -> Tuple[Optional[bytes], Optional[bytes]]:
"""从缓存中获取图标文件"""
cache_path = os.path.join(setting.icon_root_path, 'data', 'icon', domain + '.png')
cache_path = os.path.join(setting.icon_root_path, 'data', 'icon', domain_md5[:2], f"{domain_md5}.png")
if os.path.exists(cache_path) and os.path.isfile(cache_path) and os.path.getsize(cache_path) > 0:
try:
cached_icon = FileUtil.read_file(cache_path, mode='rb')
@@ -352,8 +352,8 @@ async def get_icon_async(entity: Favicon, _cached: bytes = None) -> Optional[byt
icon_content = _cached if _cached else setting.default_icon_file
if icon_content:
cache_path = os.path.join(setting.icon_root_path, 'data', 'icon', entity.domain_md5 + '.png')
md5_path = os.path.join(setting.icon_root_path, 'data', 'text', entity.domain_md5 + '.txt')
cache_path = os.path.join(setting.icon_root_path, 'data', 'icon', entity.domain_md5[:2], f"{entity.domain_md5}.png")
md5_path = os.path.join(setting.icon_root_path, 'data', 'text', entity.domain_md5[:2], f"{entity.domain_md5}.txt")
try:
# 确保目录存在
@@ -362,7 +362,7 @@ async def get_icon_async(entity: Favicon, _cached: bytes = None) -> Optional[byt
# 写入缓存文件注意文件IO操作仍然是同步的
FileUtil.write_file(cache_path, icon_content, mode='wb')
FileUtil.write_file(md5_path, entity.domain, mode='w')
FileUtil.write_file(md5_path, entity.domain)
# 任务计数
_icon_count += 1