mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-20 20:39:55 +00:00
refactor: 移除IP地址转换字符串的冗余操作
在多个文件中,`request.client.host` 已经是字符串类型,无需再使用 `str()` 进行转换。此次修改简化了代码,避免了不必要的类型转换操作。
This commit is contained in:
@@ -94,7 +94,7 @@ class LoginService:
|
||||
name=user.name,
|
||||
user_name=user.username,
|
||||
ipaddr=request.client.host,
|
||||
login_location=IpLocalUtil.get_ip_location(str(request.client.host)),
|
||||
login_location=IpLocalUtil.get_ip_location(request.client.host),
|
||||
os=user_agent.os.family,
|
||||
browser = user_agent.browser.family,
|
||||
login_time=user.last_login
|
||||
|
||||
@@ -68,7 +68,7 @@ class OperationLogRoute(APIRoute):
|
||||
current_user_id = request.scope.get("user_id")
|
||||
if request.url.path == '/api/v1/system/auth/login':
|
||||
# 只有登录的才会获取登录地址
|
||||
login_location = IpLocalUtil.get_ip_location(str(request.client.host))
|
||||
login_location = IpLocalUtil.get_ip_location(request.client.host)
|
||||
|
||||
await OperationLogService.create_log_service(data=OperationLogCreateSchema(
|
||||
request_path = request.url.path,
|
||||
|
||||
@@ -35,7 +35,7 @@ class IpLocalUtil:
|
||||
logger.error(f"IP格式不合法: {ip}")
|
||||
return "未知"
|
||||
|
||||
logger.info(f"获取IP归属地: {ip}")
|
||||
logger.info(f"获取IP归属地: {ip}, 类型: {type(ip)}")
|
||||
|
||||
# 内网IP直接返回
|
||||
if ip == '127.0.0.1' or ip == 'localhost':
|
||||
@@ -50,6 +50,7 @@ class IpLocalUtil:
|
||||
if ip_result.status_code == 200:
|
||||
|
||||
data = ip_result.json().get('data', {})
|
||||
logger.info(f"获取IP归属地成功: {data}")
|
||||
# "continent": "亚洲",
|
||||
# "country": "中国",
|
||||
# "zipcode": "710061",
|
||||
|
||||
Reference in New Issue
Block a user