mirror of
https://github.com/A-Minos/nonebot-plugin-tetris-stats.git
synced 2026-03-05 05:36:54 +08:00
✨ 添加配置项 请求超时时间
This commit is contained in:
@@ -10,3 +10,5 @@ CACHE_PATH: Path = get_cache_dir('nonebot_plugin_tetris_stats')
|
|||||||
|
|
||||||
class Config(BaseModel):
|
class Config(BaseModel):
|
||||||
"""配置类"""
|
"""配置类"""
|
||||||
|
|
||||||
|
tetris_req_timeout: float = 30.0
|
||||||
|
|||||||
@@ -7,11 +7,12 @@ from nonebot.log import logger
|
|||||||
from playwright.async_api import Response
|
from playwright.async_api import Response
|
||||||
from ujson import JSONDecodeError, dumps, loads
|
from ujson import JSONDecodeError, dumps, loads
|
||||||
|
|
||||||
from ..config.config import CACHE_PATH
|
from ..config.config import CACHE_PATH, Config
|
||||||
from .browser import BrowserManager
|
from .browser import BrowserManager
|
||||||
from .exception import RequestError
|
from .exception import RequestError
|
||||||
|
|
||||||
driver = get_driver()
|
driver = get_driver()
|
||||||
|
config = Config.parse_obj(driver.config)
|
||||||
|
|
||||||
|
|
||||||
@driver.on_startup
|
@driver.on_startup
|
||||||
@@ -115,7 +116,7 @@ class Request:
|
|||||||
async def request(cls, url: str, *, is_json: bool = True) -> bytes:
|
async def request(cls, url: str, *, is_json: bool = True) -> bytes:
|
||||||
"""请求api"""
|
"""请求api"""
|
||||||
try:
|
try:
|
||||||
async with AsyncClient(cookies=cls._cookies) as session:
|
async with AsyncClient(cookies=cls._cookies, timeout=config.tetris_req_timeout) as session:
|
||||||
response = await session.get(url, headers=cls._headers)
|
response = await session.get(url, headers=cls._headers)
|
||||||
if is_json:
|
if is_json:
|
||||||
loads(response.content)
|
loads(response.content)
|
||||||
|
|||||||
Reference in New Issue
Block a user