Улучшение обработки запросов к VNDB API и изменение структуры полей в ответах

This commit is contained in:
2026-05-01 16:26:33 +03:00
parent fefe522e46
commit c5ae63326f
2 changed files with 14 additions and 24 deletions

12
bot.py
View File

@@ -182,8 +182,8 @@ Staff: {stats.get('staff', 0)}
)
results = await vndb_client.query_vn(
filters=["search", "=", query],
fields=["title", "id", "image{url}"],
filters=["search", "=", query], # ✔️ без вложенности
fields=["id", "title", "image{url}"],
results=10
)
@@ -228,8 +228,8 @@ Staff: {stats.get('staff', 0)}
return ConversationHandler.END
results = await vndb_client.query_character(
filters=["search", "=", query],
fields=["name", "id", "image{url}"],
filters=["search", "=", query], # ✔️ важно
fields=["id", "name", "image{url}"],
results=10
)
@@ -255,8 +255,8 @@ Staff: {stats.get('staff', 0)}
query = " ".join(context.args)
results = await vndb_client.query_release(
filters=["search", "=", query],
fields=["title", "id"],
filters=["search", "=", query], # ✔️ важно
fields=["id", "title"],
results=10
)

View File

@@ -55,30 +55,20 @@ class VndbClient:
method: str = "GET",
data: Optional[Dict[str, Any]] = None,
) -> Dict[str, Any]:
"""
Make HTTP request to VNDB API
Args:
endpoint: API endpoint
method: HTTP method (GET, POST, PATCH, DELETE)
data: Request body data
Returns:
Response JSON
Raises:
httpx.HTTPError: On HTTP errors
json.JSONDecodeError: On invalid JSON response
"""
url = f"{self.base_url}{endpoint}"
async with httpx.AsyncClient(timeout=10) as client:
async with httpx.AsyncClient(timeout=15) as client:
response = await client.request(
method,
url,
headers=self.headers,
content=json.dumps(data) if data else None,
json=data if data else None, # 🔥 ВАЖНО: json= вместо content=
)
if response.status_code >= 400:
print("VNDB ERROR:", response.status_code, response.text)
response.raise_for_status()
return response.json()