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

View File

@ -371,12 +371,12 @@ def add_failed_url(domain: str):
return
try:
# 确保失败URL目录存在
os.makedirs(setting.failed_urls_dir, exist_ok=True)
# 将域名的MD5值作为文件名
domain_md5 = hashlib.md5(domain.encode("utf-8")).hexdigest()
file_path = os.path.join(setting.failed_urls_dir, f"{domain_md5}.txt")
file_path = os.path.join(setting.failed_urls_dir, domain_md5[:1], f"{domain_md5}.txt")
# 确保失败URL目录存在
os.makedirs(os.path.dirname(file_path), exist_ok=True)
# 格式化当前时间
formatted_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
@ -409,7 +409,7 @@ def is_failed_url(domain: str) -> bool:
domain_md5 = hashlib.md5(domain.encode("utf-8")).hexdigest()
domain_md5_mapping[domain] = domain_md5
file_path = os.path.join(setting.failed_urls_dir, f"{domain_md5}.txt")
file_path = os.path.join(setting.failed_urls_dir, domain_md5[:1], f"{domain_md5}.txt")
# 检查文件是否存在
if not os.path.exists(file_path):

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

View File

@ -17,7 +17,7 @@ default_icon_file = FileUtil.read_file(default_icon_path, mode='rb')
# 定义referer日志文件路径
referer_log_file = os.path.join(icon_root_path, 'data', 'referer.txt')
# 定义失败URL日志文件路径
failed_urls_file = os.path.join(icon_root_path, 'data', 'failedurls.txt')
# failed_urls_file = os.path.join(icon_root_path, 'data', 'failedurls.txt')
# 定义失败URL存储目录
failed_urls_dir = os.path.join(icon_root_path, 'data', 'failed_urls')