Skip to content

Commit

Permalink
Change according to Ashlen's review
Browse files Browse the repository at this point in the history
  • Loading branch information
seriaati committed Jun 7, 2024
1 parent fbc630a commit 380a344
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions genshin/client/components/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ class BaseClient(abc.ABC):
"authkeys",
"_hoyolab_id",
"_accounts",
"device_id",
"device_fp",
"custom_headers",
)

USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36" # noqa: E501
Expand Down Expand Up @@ -73,8 +72,7 @@ def __init__(
game: typing.Optional[types.Game] = None,
uid: typing.Optional[int] = None,
hoyolab_id: typing.Optional[int] = None,
device_id: typing.Optional[str] = None,
device_fp: typing.Optional[str] = None,
headers: typing.Optional[aiohttp.typedefs.LooseHeaders] = None,
cache: typing.Optional[client_cache.Cache] = None,
debug: bool = False,
) -> None:
Expand All @@ -93,17 +91,14 @@ def __init__(
self.proxy = proxy
self.uid = uid
self.hoyolab_id = hoyolab_id
self.device_id = device_id
self.device_fp = device_fp
self.custom_headers = headers or {}

def __repr__(self) -> str:
kwargs = dict(
lang=self.lang,
region=self.region.value,
default_game=self.default_game and self.default_game.value,
hoyolab_id=self.hoyolab_id,
device_id=self.device_id,
device_fp=self.device_fp,
uid=self.default_game and self.uid,
authkey=self.authkey and self.authkey[:12] + "...",
proxy=self.proxy,
Expand Down Expand Up @@ -304,7 +299,6 @@ async def _request_hook(
*,
params: typing.Optional[typing.Mapping[str, typing.Any]] = None,
data: typing.Any = None,
headers: typing.Dict[str, typing.Any],
**kwargs: typing.Any,
) -> None:
"""Perform an action before a request.
Expand All @@ -316,10 +310,6 @@ async def _request_hook(
params = {k: v for k, v in params.items() if k != "authkey"}
url = url.update_query(params)

headers.update(
{k: v for k, v in {"x-rpc-device_id": self.device_id, "x-rpc-device_fp": self.device_fp}.items() if v}
)

if data:
self.logger.debug("%s %s\n%s", method, url, json.dumps(data, separators=(",", ":")))
else:
Expand Down Expand Up @@ -351,6 +341,7 @@ async def request(

headers = dict(headers or {})
headers["User-Agent"] = self.USER_AGENT
headers.update(self.custom_headers)

if method is None:
method = "POST" if data else "GET"
Expand Down

0 comments on commit 380a344

Please sign in to comment.