refactor: 移除未使用的代码和注释,优化代码结构
- 删除 SettingView.vue 中的 TODO 注释 - 移除 AgentView.vue 和 AgentChatComponent.vue 中侧边栏互斥逻辑 - 删除 kb_manager.py 中未实现的 migrate_database 方法 - 将操作日志功能提取到 common_utils.py - 修复文件末尾缺少换行符的问题
This commit is contained in:
parent
9b96bd0ba6
commit
fa56bca143
@ -8,6 +8,7 @@ from server.db_manager import db_manager
|
||||
from server.models.user_model import User, OperationLog
|
||||
from server.utils.auth_utils import AuthUtils
|
||||
from server.utils.auth_middleware import get_db, get_current_user, get_admin_user, get_superadmin_user, oauth2_scheme
|
||||
from server.utils.common_utils import log_operation
|
||||
|
||||
# 创建路由器
|
||||
auth = APIRouter(prefix="/auth", tags=["authentication"])
|
||||
@ -45,20 +46,6 @@ class InitializeAdmin(BaseModel):
|
||||
# === 工具函数 ===
|
||||
# =============================================================================
|
||||
|
||||
# 记录操作日志
|
||||
def log_operation(db: Session, user_id: int, operation: str, details: str = None, request: Request = None):
|
||||
ip_address = None
|
||||
if request:
|
||||
ip_address = request.client.host if request.client else None
|
||||
|
||||
log = OperationLog(
|
||||
user_id=user_id,
|
||||
operation=operation,
|
||||
details=details,
|
||||
ip_address=ip_address
|
||||
)
|
||||
db.add(log)
|
||||
db.commit()
|
||||
|
||||
# 路由:登录获取令牌
|
||||
# =============================================================================
|
||||
|
||||
@ -450,4 +450,4 @@ async def get_knowledge_base_statistics(current_user: User = Depends(get_admin_u
|
||||
return {"stats": stats, "message": "success"}
|
||||
except Exception as e:
|
||||
logger.error(f"获取知识库统计失败 {e}, {traceback.format_exc()}")
|
||||
return {"message": f"获取知识库统计失败 {e}", "stats": {}}
|
||||
return {"message": f"获取知识库统计失败 {e}", "stats": {}}
|
||||
|
||||
26
server/utils/common_utils.py
Normal file
26
server/utils/common_utils.py
Normal file
@ -0,0 +1,26 @@
|
||||
"""通用工具函数"""
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
from fastapi import Request
|
||||
from server.models.user_model import User, OperationLog
|
||||
|
||||
|
||||
def log_operation(db: Session, user_id: int, operation: str, details: str = None, request: Request = None):
|
||||
"""记录用户操作日志"""
|
||||
ip_address = None
|
||||
if request:
|
||||
ip_address = request.client.host if request.client else None
|
||||
|
||||
log = OperationLog(
|
||||
user_id=user_id,
|
||||
operation=operation,
|
||||
details=details,
|
||||
ip_address=ip_address
|
||||
)
|
||||
db.add(log)
|
||||
db.commit()
|
||||
|
||||
|
||||
def get_user_dict(user: User, include_password: bool = False) -> dict:
|
||||
"""获取用户字典表示"""
|
||||
return user.to_dict(include_password)
|
||||
@ -298,22 +298,6 @@ class KnowledgeBaseManager:
|
||||
}
|
||||
return info
|
||||
|
||||
def migrate_database(self, db_id: str, target_kb_type: str) -> dict:
|
||||
"""
|
||||
迁移数据库到不同的知识库类型
|
||||
|
||||
Args:
|
||||
db_id: 数据库ID
|
||||
target_kb_type: 目标知识库类型
|
||||
|
||||
Returns:
|
||||
迁移结果
|
||||
|
||||
注意:这是一个复杂的操作,需要重新索引所有数据
|
||||
"""
|
||||
# TODO: 实现数据库迁移逻辑
|
||||
raise NotImplementedError("Database migration not implemented yet")
|
||||
|
||||
def get_statistics(self) -> dict:
|
||||
"""获取统计信息"""
|
||||
stats = {
|
||||
|
||||
@ -379,4 +379,4 @@ class LightRagKB(KnowledgeBase):
|
||||
# )
|
||||
|
||||
# logger.info(f"Successfully created export file: {output_filepath}")
|
||||
# return output_filepath
|
||||
# return output_filepath
|
||||
|
||||
@ -1288,10 +1288,6 @@ const scrollToBottom = async () => {
|
||||
const toggleSidebar = () => {
|
||||
state.isSidebarOpen = !state.isSidebarOpen;
|
||||
localStorage.setItem('chat_sidebar_open', state.isSidebarOpen);
|
||||
// 当打开聊天侧边栏时,关闭配置侧边栏
|
||||
if (state.isSidebarOpen) {
|
||||
emit('close-config-sidebar');
|
||||
}
|
||||
console.log("toggleSidebar", state.isSidebarOpen);
|
||||
}
|
||||
|
||||
|
||||
@ -390,10 +390,6 @@ const toggleDebugMode = () => {
|
||||
|
||||
const toggleConf = () => {
|
||||
state.isConfigSidebarOpen = !state.isConfigSidebarOpen
|
||||
// 当打开配置侧边栏时,关闭聊天侧边栏
|
||||
if (state.isConfigSidebarOpen) {
|
||||
state.isChatSidebarOpen = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
<template>
|
||||
<!-- TODO 优化样式,表格优化,添加一个 utils 的函数,用来把时间戳转换为东 8 区的时间,并格式化显示出来 -->
|
||||
<div class="">
|
||||
<HeaderComponent title="设置" class="setting-header">
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user