Skip to content

Commit

Permalink
imp: Make fetch_mi18n method more versatile
Browse files Browse the repository at this point in the history
  • Loading branch information
seriaati committed Dec 9, 2024
1 parent ad945b1 commit 5413c27
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
8 changes: 5 additions & 3 deletions genshin/client/components/hoyolab.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import typing
import warnings

import yarl

from genshin import types, utility
from genshin.client import cache as client_cache
from genshin.client import routes
Expand Down Expand Up @@ -235,12 +237,12 @@ async def check_in_community(self) -> None:

@base.region_specific(types.Region.OVERSEAS)
async def fetch_mi18n(
self, filename: str, game: types.Game, *, lang: typing.Optional[str] = None
self, url: typing.Union[str, yarl.URL], filename: str, *, lang: typing.Optional[str] = None
) -> typing.Mapping[str, str]:
"""Fetch a mi18n file."""
return await self.request(
routes.MI18N_URL.get_url(types.Region.OVERSEAS, game) / f"{filename}/{filename}-{lang or self.lang}.json",
cache=client_cache.cache_key("mi18n", filename=filename, game=game, lang=lang or self.lang),
yarl.URL(url) / f"{filename}/{filename}-{lang or self.lang}.json",
cache=client_cache.cache_key("mi18n", filename=filename, url=url, lang=lang or self.lang),
)

@base.region_specific(types.Region.OVERSEAS)
Expand Down
10 changes: 0 additions & 10 deletions genshin/client/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,4 @@ def get_url(self, region: types.Region, game: types.Game) -> yarl.URL:
chinese="https://public-data-api.mihoyo.com/device-fp/api/getFp",
)

MI18N_URL = GameRoute(
overseas=dict(
genshin="https://fastcdn.hoyoverse.com/mi18n/bbs_oversea",
hkrpg="https://webstatic.hoyoverse.com/admin/mi18n/bbs_oversea",
nap="https://fastcdn.hoyoverse.com/mi18n/nap_global",
honkai3rd="https://fastcdn.hoyoverse.com/mi18n/bbs_oversea",
),
chinese=dict(),
)

MIMO_URL = Route("https://sg-public-api.hoyolab.com/event/e2023mimotravel")

0 comments on commit 5413c27

Please sign in to comment.