mirror of
https://github.com/fastapi-practices/fastapi-best-architecture.git
synced 2026-09-22 05:22:56 +00:00
Fix offline parse ip info (#112)
* Fix get info subscript * Fix return typing
This commit is contained in:
@@ -47,7 +47,7 @@ async def get_location_online(ip: str, user_agent: str) -> dict | None:
|
||||
|
||||
|
||||
@sync_to_async
|
||||
def get_location_offline(ip: str) -> str | None:
|
||||
def get_location_offline(ip: str) -> list[str] | None:
|
||||
"""
|
||||
离线获取 ip 地址属地,无法保证准确率,100%可用
|
||||
|
||||
@@ -79,8 +79,8 @@ async def parse_ip_info(request: Request) -> tuple[str, str, str, str]:
|
||||
location_info = await get_location_offline(ip)
|
||||
if location_info:
|
||||
country = location_info[0] if location_info[0] != '0' else None
|
||||
region = location_info[1] if location_info[1] != '0' else None
|
||||
city = location_info[2] if location_info[2] != '0' else None
|
||||
region = location_info[2] if location_info[2] != '0' else None
|
||||
city = location_info[3] if location_info[3] != '0' else None
|
||||
return ip, country, region, city
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user