敏感词列表

This commit is contained in:
ZZX9599
2025-09-03 23:01:04 +08:00
parent 9a3e5be99f
commit 834de70547

View File

@ -107,9 +107,7 @@ async def get_sensitive(
# 3. 获取所有敏感信息记录 # 3. 获取所有敏感信息记录
# ------------------------------ # ------------------------------
@router.get("", response_model=APIResponse, summary="获取所有敏感信息记录") @router.get("", response_model=APIResponse, summary="获取所有敏感信息记录")
async def get_all_sensitives( async def get_all_sensitives():
current_user: UserResponse = Depends(get_current_user) # 需登录认证
):
""" """
获取所有敏感信息记录: 获取所有敏感信息记录:
- 需登录认证 - 需登录认证
@ -256,3 +254,36 @@ async def delete_sensitive(
raise Exception(f"删除敏感信息记录失败:{str(e)}") from e raise Exception(f"删除敏感信息记录失败:{str(e)}") from e
finally: finally:
db.close_connection(conn, cursor) db.close_connection(conn, cursor)
def get_all_sensitive_words() -> list[str]:
"""
获取所有敏感词,返回字符串数组
返回:
list[str]: 包含所有敏感词的数组
异常:
MySQLError: 数据库操作相关错误
"""
conn = None
cursor = None
try:
# 获取数据库连接
conn = db.get_connection()
cursor = conn.cursor(dictionary=True)
# 执行查询,只获取敏感词字段
query = "SELECT name FROM sensitives ORDER BY id"
cursor.execute(query)
sensitive_records = cursor.fetchall()
# 提取敏感词到数组中
return [record['name'] for record in sensitive_records]
except MySQLError as e:
# 数据库错误处理
raise MySQLError(f"查询敏感词失败:{str(e)}") from e
finally:
# 确保资源正确释放
db.close_connection(conn, cursor)