缓存错误的身份码,避免旧版的请求传到开放平台

pull/140/head
John Smith 1 year ago
parent 05fc89dbbe
commit 63ef4ac971

@ -10,6 +10,7 @@ import re
from typing import *
import aiohttp
import cachetools
import tornado.web
import api.base
@ -27,6 +28,8 @@ START_GAME_COMMON_SERVER_URL = COMMON_SERVER_BASE_URL + '/api/internal/open_live
END_GAME_COMMON_SERVER_URL = COMMON_SERVER_BASE_URL + '/api/internal/open_live/end_game'
GAME_HEARTBEAT_COMMON_SERVER_URL = COMMON_SERVER_BASE_URL + '/api/internal/open_live/game_heartbeat'
_error_auth_code_cache = cachetools.LRUCache(256)
class TransportError(Exception):
"""网络错误或HTTP状态码错误"""
@ -66,7 +69,10 @@ async def _request_open_live(url, body: dict) -> dict:
# 输错身份码的人太多了临时处理屏蔽请求不然要被B站下架了
if url == START_GAME_OPEN_LIVE_URL:
_validate_auth_code(body.get('code', ''))
auth_code = body.get('code', '')
_validate_auth_code(auth_code)
else:
auth_code = ''
body_bytes = json.dumps(body).encode('utf-8')
headers = {
@ -98,6 +104,8 @@ async def _request_open_live(url, body: dict) -> dict:
raise
except BusinessError as e:
logger.warning('Request open live failed: %s', e)
if e.code == 7007:
_error_auth_code_cache[auth_code] = True
raise
@ -115,12 +123,14 @@ async def _read_response(req_ctx_mgr: AsyncContextManager[aiohttp.ClientResponse
def _validate_auth_code(auth_code):
if (
auth_code in _error_auth_code_cache
# 我也不知道是不是一定是这个格式,先临时这么处理
if re.fullmatch(r'[0-9A-Z]{12,14}', auth_code):
return
or not re.fullmatch(r'[0-9A-Z]{12,14}', auth_code)
):
raise BusinessError({
'code': 7007,
'message': '身份码错误',
'message': 'oioioi你的身份码错误了!别再重试了!!!!!!!!!!',
'request_id': '0',
'data': None
})

Loading…
Cancel
Save