This commit is contained in:
jinql
2025-09-03 20:07:41 +08:00
parent a5290c5e03
commit 452e110ee5
15 changed files with 156 additions and 47 deletions

View File

@@ -20,7 +20,7 @@ from favicon_app.utils.filetype import helpers, filetype
urllib3.disable_warnings()
logging.captureWarnings(True)
# 配置日志
logger = logging.getLogger()
logger = logging.getLogger(__name__)
# 创建requests会话池
requests_session = requests.Session()

View File

@@ -13,7 +13,7 @@ from favicon_app.utils.file_util import FileUtil
urllib3.disable_warnings()
logging.captureWarnings(True)
logger = logging.getLogger()
logger = logging.getLogger(__name__)
_icon_root_path = favicon_service.icon_root_path
_default_icon_path = favicon_service.default_icon_path
@@ -58,7 +58,7 @@ async def get_count():
async def get_referrer():
"""获取请求来源信息"""
content = 'None'
path = os.path.join(_icon_root_path, 'referrer.txt')
path = os.path.join(_icon_root_path, 'conf', 'referrer.txt')
if os.path.exists(path):
try:
content = FileUtil.read_file(path, mode='r') or 'None'

View File

@@ -23,7 +23,7 @@ from favicon_app.utils.filetype import helpers, filetype
urllib3.disable_warnings()
logging.captureWarnings(True)
logger = logging.getLogger()
logger = logging.getLogger(__name__)
# 获取当前所在目录的绝对路径
current_dir = os.path.dirname(os.path.abspath(__file__))
@@ -127,7 +127,7 @@ class FaviconService:
def _get_cache_file(self, domain: str, refresh: bool = False) -> Tuple[Optional[bytes], Optional[bytes]]:
"""从缓存中获取图标文件"""
cache_path = os.path.join(icon_root_path, 'icon', domain + '.png')
cache_path = os.path.join(icon_root_path, 'data/icon', domain + '.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')
@@ -269,7 +269,7 @@ class FaviconService:
if _referrer:
logger.debug(f"-> Referrer: {_referrer}")
_path = os.path.join(icon_root_path, 'referrer.txt')
_path = os.path.join(icon_root_path, 'conf', 'referrer.txt')
with self._lock:
# 首次加载现有referrer数据
@@ -336,8 +336,8 @@ class FaviconService:
icon_content = _cached if _cached else default_icon_content
if icon_content:
cache_path = os.path.join(icon_root_path, 'icon', entity.domain_md5 + '.png')
md5_path = os.path.join(icon_root_path, 'md5', entity.domain_md5 + '.txt')
cache_path = os.path.join(icon_root_path, 'data/icon', entity.domain_md5 + '.png')
md5_path = os.path.join(icon_root_path, 'data/text', entity.domain_md5 + '.txt')
try:
# 确保目录存在
@@ -391,6 +391,7 @@ class FaviconService:
if not url:
return {"message": "请提供url参数"}
logger.info('##########################################################')
try:
entity = Favicon(url)

View File

@@ -10,7 +10,7 @@ import urllib3
# 配置日志
urllib3.disable_warnings()
logging.captureWarnings(True)
logger = logging.getLogger()
logger = logging.getLogger(__name__)
class FileUtil:
@@ -244,7 +244,7 @@ class FileUtil:
with open(file_path, mode, encoding=encoding) as f:
f.write(content)
logger.info(f"文件写入成功: {file_path}")
# logger.info(f"文件写入成功: {file_path}")
return True
except PermissionError:
logger.error(f"没有权限写入文件: {file_path}")