🎈 auto fixes by pre-commit hooks
This commit is contained in:
@@ -84,9 +84,13 @@ async def download_image_by_url(
|
||||
下载图片, 返回 path
|
||||
"""
|
||||
try:
|
||||
ssl_context = ssl.create_default_context(cafile=certifi.where()) # 使用 certifi 提供的 CA 证书
|
||||
ssl_context = ssl.create_default_context(
|
||||
cafile=certifi.where()
|
||||
) # 使用 certifi 提供的 CA 证书
|
||||
connector = aiohttp.TCPConnector(ssl=ssl_context) # 使用 certifi 的根证书
|
||||
async with aiohttp.ClientSession(trust_env=True, connector=connector) as session:
|
||||
async with aiohttp.ClientSession(
|
||||
trust_env=True, connector=connector
|
||||
) as session:
|
||||
if post:
|
||||
async with session.post(url, json=post_data) as resp:
|
||||
if not path:
|
||||
@@ -123,9 +127,13 @@ async def download_file(url: str, path: str, show_progress: bool = False):
|
||||
从指定 url 下载文件到指定路径 path
|
||||
"""
|
||||
try:
|
||||
ssl_context = ssl.create_default_context(cafile=certifi.where()) # 使用 certifi 提供的 CA 证书
|
||||
ssl_context = ssl.create_default_context(
|
||||
cafile=certifi.where()
|
||||
) # 使用 certifi 提供的 CA 证书
|
||||
connector = aiohttp.TCPConnector(ssl=ssl_context)
|
||||
async with aiohttp.ClientSession(trust_env=True, connector=connector) as session:
|
||||
async with aiohttp.ClientSession(
|
||||
trust_env=True, connector=connector
|
||||
) as session:
|
||||
async with session.get(url, timeout=1800) as resp:
|
||||
if resp.status != 200:
|
||||
raise Exception(f"下载文件失败: {resp.status}")
|
||||
@@ -209,7 +217,9 @@ async def download_dashboard():
|
||||
"""下载管理面板文件"""
|
||||
dashboard_release_url = "https://astrbot-registry.soulter.top/download/astrbot-dashboard/latest/dist.zip"
|
||||
try:
|
||||
ssl_context = ssl.create_default_context(cafile=certifi.where()) # 使用 certifi 提供的 CA 证书
|
||||
ssl_context = ssl.create_default_context(
|
||||
cafile=certifi.where()
|
||||
) # 使用 certifi 提供的 CA 证书
|
||||
await download_file(
|
||||
dashboard_release_url, "data/dashboard.zip", show_progress=True
|
||||
)
|
||||
|
||||
@@ -37,14 +37,22 @@ class RepoZipUpdator:
|
||||
返回一个列表,每个元素是一个字典,包含版本号、发布时间、更新内容、commit hash等信息。
|
||||
"""
|
||||
try:
|
||||
ssl_context = ssl.create_default_context(cafile=certifi.where()) # 新增:创建基于 certifi 的 SSL 上下文
|
||||
connector = aiohttp.TCPConnector(ssl=ssl_context) # 新增:使用 TCPConnector 指定 SSL 上下文
|
||||
async with aiohttp.ClientSession(trust_env=True, connector=connector) as session:
|
||||
ssl_context = ssl.create_default_context(
|
||||
cafile=certifi.where()
|
||||
) # 新增:创建基于 certifi 的 SSL 上下文
|
||||
connector = aiohttp.TCPConnector(
|
||||
ssl=ssl_context
|
||||
) # 新增:使用 TCPConnector 指定 SSL 上下文
|
||||
async with aiohttp.ClientSession(
|
||||
trust_env=True, connector=connector
|
||||
) as session:
|
||||
async with session.get(url) as response:
|
||||
# 检查 HTTP 状态码
|
||||
if response.status != 200:
|
||||
text = await response.text()
|
||||
logger.error(f"请求 {url} 失败,状态码: {response.status}, 内容: {text}")
|
||||
logger.error(
|
||||
f"请求 {url} 失败,状态码: {response.status}, 内容: {text}"
|
||||
)
|
||||
raise Exception(f"请求失败,状态码: {response.status}")
|
||||
result = await response.json()
|
||||
if not result:
|
||||
|
||||
@@ -74,7 +74,9 @@ class PluginRoute(Route):
|
||||
connector = aiohttp.TCPConnector(ssl=ssl_context)
|
||||
for url in urls:
|
||||
try:
|
||||
async with aiohttp.ClientSession(trust_env=True, connector=connector) as session:
|
||||
async with aiohttp.ClientSession(
|
||||
trust_env=True, connector=connector
|
||||
) as session:
|
||||
async with session.get(url) as response:
|
||||
if response.status == 200:
|
||||
result = await response.json()
|
||||
|
||||
Reference in New Issue
Block a user