chore(deps): auto fix by pre-commit hooks

This commit is contained in:
pre-commit-ci[bot]
2025-08-24 03:18:58 +00:00
committed by MingxuanGame
parent b4fd4e0256
commit 7625cd99f5
25 changed files with 241 additions and 320 deletions

View File

@@ -5,27 +5,29 @@
from __future__ import annotations
from typing import Any
from fastapi import Request
from app.config import settings
from app.service.asset_proxy_service import get_asset_proxy_service
from fastapi import Request
async def process_response_assets(data: Any, request: Request) -> Any:
"""
根据配置处理响应数据中的资源URL
Args:
data: API响应数据
request: FastAPI请求对象
Returns:
处理后的数据
"""
if not settings.enable_asset_proxy:
return data
asset_service = get_asset_proxy_service()
# 仅URL替换模式
return await asset_service.replace_asset_urls(data)
@@ -47,7 +49,7 @@ def should_process_asset_proxy(path: str) -> bool:
"/api/v2/beatmapsets/",
# 可以根据需要添加更多端点
]
return any(path.startswith(endpoint) for endpoint in asset_proxy_endpoints)
@@ -56,6 +58,7 @@ def asset_proxy_response(func):
"""
装饰器自动处理响应中的资源URL
"""
async def wrapper(*args, **kwargs):
# 获取request对象
request = None
@@ -63,14 +66,14 @@ def asset_proxy_response(func):
if isinstance(arg, Request):
request = arg
break
# 执行原函数
result = await func(*args, **kwargs)
# 如果有request对象且启用了资源代理则处理响应
if request and settings.enable_asset_proxy and should_process_asset_proxy(request.url.path):
result = await process_response_assets(result, request)
return result
return wrapper