Browse Source

feat: 后端配置文件新增IP归属区域查询开关配置

master
insistence 10 months ago
parent
commit
a57d737261
  1. 2
      ruoyi-fastapi-backend/.env.dev
  2. 2
      ruoyi-fastapi-backend/.env.prod
  3. 1
      ruoyi-fastapi-backend/config/env.py
  4. 3
      ruoyi-fastapi-backend/module_admin/annotation/log_annotation.py

2
ruoyi-fastapi-backend/.env.dev

@ -13,6 +13,8 @@ APP_PORT = 9099
APP_VERSION= '1.0.3' APP_VERSION= '1.0.3'
# 应用是否开启热重载 # 应用是否开启热重载
APP_RELOAD = true APP_RELOAD = true
# 应用是否开启IP归属区域查询
APP_IP_LOCATION_QUERY = true
# -------- Jwt配置 -------- # -------- Jwt配置 --------
# Jwt秘钥 # Jwt秘钥

2
ruoyi-fastapi-backend/.env.prod

@ -13,6 +13,8 @@ APP_PORT = 9099
APP_VERSION= '1.0.3' APP_VERSION= '1.0.3'
# 应用是否开启热重载 # 应用是否开启热重载
APP_RELOAD = false APP_RELOAD = false
# 应用是否开启IP归属区域查询
APP_IP_LOCATION_QUERY = true
# -------- Jwt配置 -------- # -------- Jwt配置 --------
# Jwt秘钥 # Jwt秘钥

1
ruoyi-fastapi-backend/config/env.py

@ -17,6 +17,7 @@ class AppSettings(BaseSettings):
app_port: int = 9099 app_port: int = 9099
app_version: str = '1.0.0' app_version: str = '1.0.0'
app_reload: bool = True app_reload: bool = True
app_ip_location_query: bool = True
class JwtSettings(BaseSettings): class JwtSettings(BaseSettings):

3
ruoyi-fastapi-backend/module_admin/annotation/log_annotation.py

@ -12,6 +12,7 @@ from typing import Optional
from module_admin.service.login_service import LoginService from module_admin.service.login_service import LoginService
from module_admin.service.log_service import OperationLogService, LoginLogService from module_admin.service.log_service import OperationLogService, LoginLogService
from module_admin.entity.vo.log_vo import OperLogModel, LogininforModel from module_admin.entity.vo.log_vo import OperLogModel, LogininforModel
from config.env import AppConfig
def log_decorator(title: str, business_type: int, log_type: Optional[str] = 'operation'): def log_decorator(title: str, business_type: int, log_type: Optional[str] = 'operation'):
@ -50,6 +51,7 @@ def log_decorator(title: str, business_type: int, log_type: Optional[str] = 'ope
# 获取请求的ip及ip归属区域 # 获取请求的ip及ip归属区域
oper_ip = request.headers.get("X-Forwarded-For") oper_ip = request.headers.get("X-Forwarded-For")
oper_location = '内网IP' oper_location = '内网IP'
if AppConfig.app_ip_location_query:
try: try:
if oper_ip != '127.0.0.1' and oper_ip != 'localhost': if oper_ip != '127.0.0.1' and oper_ip != 'localhost':
ip_result = requests.get(f'https://qifu-api.baidubce.com/ip/geo/v1/district?ip={oper_ip}') ip_result = requests.get(f'https://qifu-api.baidubce.com/ip/geo/v1/district?ip={oper_ip}')
@ -65,7 +67,6 @@ def log_decorator(title: str, business_type: int, log_type: Optional[str] = 'ope
except Exception as e: except Exception as e:
oper_location = '未知' oper_location = '未知'
print(e) print(e)
finally:
# 根据不同的请求类型使用不同的方法获取请求参数 # 根据不同的请求类型使用不同的方法获取请求参数
content_type = request.headers.get("Content-Type") content_type = request.headers.get("Content-Type")
if content_type and ("multipart/form-data" in content_type or 'application/x-www-form-urlencoded' in content_type): if content_type and ("multipart/form-data" in content_type or 'application/x-www-form-urlencoded' in content_type):

Loading…
Cancel
Save