25.09.01
parent
d963287cda
commit
ae0001f3ab
|
@ -1,4 +1,4 @@
|
||||||
FROM python:3.11-slim
|
FROM python:3.13-slim
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,8 @@ from fastapi import Request
|
||||||
from fastapi.responses import Response
|
from fastapi.responses import Response
|
||||||
|
|
||||||
from favicon_app.models import Favicon
|
from favicon_app.models import Favicon
|
||||||
from favicon_app.utils import header, file_util
|
from favicon_app.utils import header
|
||||||
|
from favicon_app.utils.file_util import FileUtil
|
||||||
from favicon_app.utils.filetype import helpers, filetype
|
from favicon_app.utils.filetype import helpers, filetype
|
||||||
|
|
||||||
urllib3.disable_warnings()
|
urllib3.disable_warnings()
|
||||||
|
@ -30,7 +31,7 @@ current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
# icon 存储的绝对路径,上两级目录
|
# icon 存储的绝对路径,上两级目录
|
||||||
icon_root_path = os.path.abspath(os.path.join(current_dir, '..', '..'))
|
icon_root_path = os.path.abspath(os.path.join(current_dir, '..', '..'))
|
||||||
default_icon_path = os.path.join(icon_root_path, 'favicon.png')
|
default_icon_path = os.path.join(icon_root_path, 'favicon.png')
|
||||||
default_icon_content = file_util.read_file(default_icon_path, mode='rb')
|
default_icon_content = FileUtil.read_file(default_icon_path, mode='rb')
|
||||||
|
|
||||||
|
|
||||||
class FaviconService:
|
class FaviconService:
|
||||||
|
@ -133,7 +134,7 @@ class FaviconService:
|
||||||
cache_path = os.path.join(icon_root_path, 'icon', domain + '.png')
|
cache_path = os.path.join(icon_root_path, 'icon', domain + '.png')
|
||||||
if os.path.exists(cache_path) and os.path.isfile(cache_path) and os.path.getsize(cache_path) > 0:
|
if os.path.exists(cache_path) and os.path.isfile(cache_path) and os.path.getsize(cache_path) > 0:
|
||||||
try:
|
try:
|
||||||
cached_icon = file_util.read_file(cache_path, mode='rb')
|
cached_icon = FileUtil.read_file(cache_path, mode='rb')
|
||||||
file_time = int(os.path.getmtime(cache_path))
|
file_time = int(os.path.getmtime(cache_path))
|
||||||
|
|
||||||
# 验证是否为有效的图片文件
|
# 验证是否为有效的图片文件
|
||||||
|
@ -284,7 +285,7 @@ class FaviconService:
|
||||||
if _referrer not in self.href_referrer:
|
if _referrer not in self.href_referrer:
|
||||||
self.href_referrer.add(_referrer)
|
self.href_referrer.add(_referrer)
|
||||||
try:
|
try:
|
||||||
file_util.write_file(_path, f'{_referrer}\n', mode='a')
|
FileUtil.write_file(_path, f'{_referrer}\n', mode='a')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"写入referrer文件失败: {e}")
|
logger.error(f"写入referrer文件失败: {e}")
|
||||||
|
|
||||||
|
@ -345,8 +346,8 @@ class FaviconService:
|
||||||
os.makedirs(os.path.dirname(md5_path), exist_ok=True)
|
os.makedirs(os.path.dirname(md5_path), exist_ok=True)
|
||||||
|
|
||||||
# 写入缓存文件
|
# 写入缓存文件
|
||||||
file_util.write_file(cache_path, icon_content, mode='wb')
|
FileUtil.write_file(cache_path, icon_content, mode='wb')
|
||||||
file_util.write_file(md5_path, entity.domain, mode='w')
|
FileUtil.write_file(md5_path, entity.domain, mode='w')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"写入缓存文件失败: {e}")
|
logger.error(f"写入缓存文件失败: {e}")
|
||||||
|
|
||||||
|
|
|
@ -5,9 +5,12 @@ import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Dict, Any, Optional, Union
|
from typing import List, Dict, Any, Optional, Union
|
||||||
|
|
||||||
|
import urllib3
|
||||||
|
|
||||||
# 配置日志
|
# 配置日志
|
||||||
logging.basicConfig(level=logging.INFO)
|
urllib3.disable_warnings()
|
||||||
logger = logging.getLogger(__name__)
|
logging.captureWarnings(True)
|
||||||
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
class FileUtil:
|
class FileUtil:
|
||||||
|
|
Loading…
Reference in New Issue