mirror of
https://github.com/xfgryujk/blivechat.git
synced 2025-03-23 08:10:56 +08:00
缓存错误的身份码,避免旧版的请求传到开放平台
This commit is contained in:
parent
05fc89dbbe
commit
63ef4ac971
@ -10,6 +10,7 @@ import re
|
|||||||
from typing import *
|
from typing import *
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
import cachetools
|
||||||
import tornado.web
|
import tornado.web
|
||||||
|
|
||||||
import api.base
|
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'
|
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'
|
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):
|
class TransportError(Exception):
|
||||||
"""网络错误或HTTP状态码错误"""
|
"""网络错误或HTTP状态码错误"""
|
||||||
@ -66,7 +69,10 @@ async def _request_open_live(url, body: dict) -> dict:
|
|||||||
|
|
||||||
# 输错身份码的人太多了,临时处理屏蔽请求,不然要被B站下架了
|
# 输错身份码的人太多了,临时处理屏蔽请求,不然要被B站下架了
|
||||||
if url == START_GAME_OPEN_LIVE_URL:
|
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')
|
body_bytes = json.dumps(body).encode('utf-8')
|
||||||
headers = {
|
headers = {
|
||||||
@ -98,6 +104,8 @@ async def _request_open_live(url, body: dict) -> dict:
|
|||||||
raise
|
raise
|
||||||
except BusinessError as e:
|
except BusinessError as e:
|
||||||
logger.warning('Request open live failed: %s', e)
|
logger.warning('Request open live failed: %s', e)
|
||||||
|
if e.code == 7007:
|
||||||
|
_error_auth_code_cache[auth_code] = True
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
@ -115,15 +123,17 @@ async def _read_response(req_ctx_mgr: AsyncContextManager[aiohttp.ClientResponse
|
|||||||
|
|
||||||
|
|
||||||
def _validate_auth_code(auth_code):
|
def _validate_auth_code(auth_code):
|
||||||
# 我也不知道是不是一定是这个格式,先临时这么处理
|
if (
|
||||||
if re.fullmatch(r'[0-9A-Z]{12,14}', auth_code):
|
auth_code in _error_auth_code_cache
|
||||||
return
|
# 我也不知道是不是一定是这个格式,先临时这么处理
|
||||||
raise BusinessError({
|
or not re.fullmatch(r'[0-9A-Z]{12,14}', auth_code)
|
||||||
'code': 7007,
|
):
|
||||||
'message': '身份码错误',
|
raise BusinessError({
|
||||||
'request_id': '0',
|
'code': 7007,
|
||||||
'data': None
|
'message': 'oi!oi!oi!你的身份码错误了!别再重试了!!!!!!!!!!',
|
||||||
})
|
'request_id': '0',
|
||||||
|
'data': None
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
class _OpenLiveHandlerBase(api.base.ApiHandler):
|
class _OpenLiveHandlerBase(api.base.ApiHandler):
|
||||||
|
Loading…
Reference in New Issue
Block a user