from infra.models.constants import UserRegion class RegionHandler: def __init__(self): self._zh_cn_patterns = [".cn", "cn.", "host"] def detect_from_host(self, host: str) -> UserRegion: # Now we set user preferred region based on host for parttern in self._zh_cn_patterns: if parttern in host.lower(): return UserRegion.ZH_CN return UserRegion.OTHER # async def get_user_region(self, user_id: str) -> UserRegion: # user_profile = await BasicProfileDoc.find_one( # BasicProfileDoc.user_id == user_id # ) # return user_profile.region if user_profile else UserRegion.OTHER