From cc2c1931dafdd429dd3fb668c4b2d1169c1da502 Mon Sep 17 00:00:00 2001 From: zhangtao <9480807882@qq.com> Date: Sun, 18 May 2025 19:22:30 +0800 Subject: [PATCH] =?UTF-8?q?fix(ip):=20=E4=BF=AE=E5=A4=8D=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E6=97=B6=E8=8E=B7=E5=8F=96=20IP=20=E5=BD=92=E5=B1=9E=E5=9C=B0?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 LoginService 和 OperationLogRoute 中,将 request.client.host 转换为字符串后再传递给 IpLocalUtil.get_ip_location - 在 IpLocalUtil 类中添加日志记录 IP 归属地获取过程 --- backend/app/api/v1/services/system/auth_service.py | 2 +- backend/app/core/router_class.py | 2 +- backend/app/utils/ip_local_util.py | 4 +++- start.sh | 11 +++++++++++ 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 start.sh diff --git a/backend/app/api/v1/services/system/auth_service.py b/backend/app/api/v1/services/system/auth_service.py index a6ac6889..aa1c1734 100644 --- a/backend/app/api/v1/services/system/auth_service.py +++ b/backend/app/api/v1/services/system/auth_service.py @@ -94,7 +94,7 @@ class LoginService: name=user.name, user_name=user.username, ipaddr=request.client.host, - login_location=IpLocalUtil.get_ip_location(request.client.host), + login_location=IpLocalUtil.get_ip_location(str(request.client.host)), os=user_agent.os.family, browser = user_agent.browser.family, login_time=user.last_login diff --git a/backend/app/core/router_class.py b/backend/app/core/router_class.py index 18759b4b..19054d98 100644 --- a/backend/app/core/router_class.py +++ b/backend/app/core/router_class.py @@ -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(request.client.host) + login_location = IpLocalUtil.get_ip_location(str(request.client.host)) await OperationLogService.create_log_service(data=OperationLogCreateSchema( request_path = request.url.path, diff --git a/backend/app/utils/ip_local_util.py b/backend/app/utils/ip_local_util.py index 898b765d..df97c8b8 100644 --- a/backend/app/utils/ip_local_util.py +++ b/backend/app/utils/ip_local_util.py @@ -34,7 +34,9 @@ class IpLocalUtil: if not cls.is_valid_ip(ip): logger.error(f"IP格式不合法: {ip}") return "未知" - + + logger.info(f"获取IP归属地: {ip}") + # 内网IP直接返回 if ip == '127.0.0.1' or ip == 'localhost': return '内网IP' diff --git a/start.sh b/start.sh new file mode 100644 index 00000000..daebcfbd --- /dev/null +++ b/start.sh @@ -0,0 +1,11 @@ +cd /home +rm -rf fastapi_vue3_admin/ +git clone https://gitee.com/tao__tao/fastapi_vue3_admin.git +cd fastapi_vue3_admin/frontend +npm install +npm run build +cd home/fastapi_vue3_admin +docker compose kill +docker compose build +docker compose up -d --force-recreate +