You've already forked favicon-api-async
25.09.23
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user